Azzera filtri
Azzera filtri

How to do a function of equations?

2 visualizzazioni (ultimi 30 giorni)
Jurgen
Jurgen il 16 Set 2014
Commentato: Jurgen il 16 Set 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 Commenti
Physiker192
Physiker192 il 16 Set 2014
could you please give more details like a little example so we can help you?
Jurgen
Jurgen il 16 Set 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.

Accedi per commentare.

Risposta accettata

Mischa Kim
Mischa Kim il 16 Set 2014
Modificato: Mischa Kim il 16 Set 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 Commenti
Jurgen
Jurgen il 16 Set 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 il 16 Set 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by