Using fsolve for equations

I have a function of two variables,
let us say F=2*x(1)-3*exp(x(2))
I am trying to use fsolve to solve the equation F=0:
x0=[1;1]
options=optimset('Display', 'iter');
[m,fval]=fsolve(@myfun, x0, options);
My question is what if my function is F=y*x(1)-3*exp(x(2)) where y is a constant that i want to pass to F such that
if y=2, F=2*x(1)-3*exp(x(2))
if y=5, F=5*x(1)-3*exp(x(2))
then ... and variables are x(1) and x(2) only?

Réponses (1)

Matt J
Matt J le 9 Oct 2013
Modifié(e) : Matt J le 9 Oct 2013

0 votes

y=whatever;
F=@(x) y*x(1)-3*exp(x(2));
Not sure how you're going to solve for 2 unknowns with only 1 equation, though.

2 commentaires

Manish
Manish le 9 Oct 2013
i am not going to solve two variables with one equation.... i just asked with an equation... i have multiple equations and variables...
How to use it if i have, let us say, 2 equations and two variables and there is one parameter T that i want to pass... e.g. F(1)=T*x(1)-3*exp(x(2)) F(2)=4*T*x(1)-3*exp(x(2)) and T is what i want to pass....
Matt J
Matt J le 9 Oct 2013
Same idea. Just make F return a vector instead of a scalar. See also

Connectez-vous pour commenter.

Produits

Tags

Question posée :

le 9 Oct 2013

Commenté :

le 9 Oct 2013

Community Treasure Hunt

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

Start Hunting!

Translated by