How to do a function of equations?

조회 수: 2 (최근 30일)
Jurgen
Jurgen 2014년 9월 16일
댓글: Jurgen 2014년 9월 16일
I want to make a function using 4 equations, something like fun = @ (w, x, y, z) [eq1, eq2, eq3; eq4], however it does not work. The only way that the function has worked is directly copying the value of each of the four equations in the function, However this does not help me because the function is inside a iterative cycle where the value of the equations change between each iteration. Is any way of solve my problem?
Thanks in advance!
  댓글 수: 2
Physiker192
Physiker192 2014년 9월 16일
could you please give more details like a little example so we can help you?
Jurgen
Jurgen 2014년 9월 16일
I mean something like:
syms x y
eq1= x*y +10;
eq2= x^y;
fun=@(x,y)[eq1,eq2];
fun(0,0)
ans = [ x*y + 10, x^y]
In the example the function is not evaluated in x and y. In my problem I obtain the equations after a serie of operations, so I need to find a way of transform them in a function.
The reason why I need to transform the equations in a function is because they have some unknowns constants then pretend to find numerically.

댓글을 달려면 로그인하십시오.

채택된 답변

Mischa Kim
Mischa Kim 2014년 9월 16일
편집: Mischa Kim 2014년 9월 16일
Jurgen, do you mean something like:
eq1 = @(x) x(1)*x(2);
eq2 = @(y) y(1) - 2;
fun = @(z) [eq1(z); eq2(z)];
fun([3,2])
ans =
6
1
  댓글 수: 4
Jurgen
Jurgen 2014년 9월 16일
Thanks again! It is almost what I need!, however is not worked yet because I have a numerical integral in the equation. To be more clear I'm going to explain a little of the problem. I have,
q1_3=1740*lambda10 + 518*exp(t/10)
and I need to compute the followinng function,
fun=@(lambda10, tau, T1) integral(@(t)(1740*lambda10 + 518*exp(t/10)),tau,T1,'ArrayValued',true)
So if I do it in that way, it works. But would have to copy "by hand" the equation q1_3. That is not feasible because each iteration change q1_3. I tried to do with matlabFunction in the following way,
integrando1=matlabFunction(q1_3);
fun=matlabFunction(integral(@(t)integrando1(lambda10,t),tau,T1,'ArrayValued',true))
but I have a error,
Error using integral (line 86) A and B must be floating point scalars.
I understand that the error is because it can not calculate the integral because the limits are still unknowns, but for now I do not want to calculate this integral, only define it as a function.
Jurgen
Jurgen 2014년 9월 16일
I got it! I did the following,
integrando1=matlabFunction(q1_3);
fun=@(lambda10,tau,T1)(integral(@(t)integrando1(lambda10,t),tau,T1,'ArrayValued',true))
Thanks you so much Mischa Kim!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by