How to do a function of equations?

2 Ansichten (letzte 30 Tage)
Jurgen
Jurgen am 16 Sep. 2014
Kommentiert: Jurgen am 16 Sep. 2014
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 Kommentare
Physiker192
Physiker192 am 16 Sep. 2014
could you please give more details like a little example so we can help you?
Jurgen
Jurgen am 16 Sep. 2014
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mischa Kim
Mischa Kim am 16 Sep. 2014
Bearbeitet: Mischa Kim am 16 Sep. 2014
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 Kommentare
Jurgen
Jurgen am 16 Sep. 2014
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 am 16 Sep. 2014
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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by