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 Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by