How to do a function of equations?

2 次查看(过去 30 天)
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 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by