help with functions inside fsolve
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi guys, im new in matlab and i have this questions. im using fsolve for 3x3 non linear equations. so as far i can understand i define my system of equations as
function f = func( x )
f(1)=a*2*x(1) - b*x(2) - exp(-x(1));
f(2)=-c*x(1) + 2*x(2) - d*exp(-x(2))];
end
but in the model the constants a to d depend in the values iterated of "x", for example, for each x(1) and x(2) i gonna have differents values of a to d so i define a new function like this
function [a b c d] = const( x )
a=x(1)*3;
b=x(2)*5;
c=x(1)+x(2);
d=x(1)/3;
so my question is, is it right to call the function const" from the function "func like this:
function f = func( x )
[a b c d] = const ( x )
f(1)=a*2*x(1) - b*x(2) - exp(-x(1));
f(2)=-c*x(1) + 2*x(2) - d*exp(-x(2))];
end
in other hand, my equations are so complex, and i want to reduce the f(1) and f(2) defining a new fuction for example if i consider
f(1)=a*2*x(1) - b*x(2) - exp(-x(1)) =A - B - C
f(2)=-c*x(1) + 2*x(2) - d*exp(-x(2))]=D + E - F
and make a new function like this
[A B C D E F] = fcont( x, a , b , c ,d )
A=a*2*x(1)
B=b*x(2)
C=exp(-x(1))
D=-c*x(1)
E=2*x(2)
F= d*exp(-x(2))
and finally have a func file that have inside two functions like this
function f = func( x )
[a b c d] = const ( x )
[A B C D E F] = fconst( x, a , b , c ,d )
f(1)=A-B -C;
f(2)=-D + E -F;
is it well planned? or just i mess everything? i wait for your answers!!
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur IEC Certification Kit (for ISO 26262 and IEC 61508) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!