I was looking in the Help menu in Matlab and they gave an example using the "fsolve" command. When trying to do the same exact example, I was getting an error. Here is what the example in the Help menu says:
"First, write an M-file that computes F, the values
of the equations at x.
function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
-x(1) + 2*x(2) - exp(-x(2))];
Next, call an optimization routine.
x0 = [-5; -5]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfun,x0,options) % Call optimizer"
So I made the following into an M file:
"function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
-x(1) + 2*x(2) - exp(-x(2))];
x0 = [-5; -5]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfun,x0,options) % Call optimizer"
When I try to run this code I get the error:
??? Input argument "x" is undefined.
Error in ==> fun1 at 3
F = [2*x(1) - x(2) - exp(-x(1));
Does anyone know what is wrong or how I can fix this problem? Any help would be great, thanks.
"First, write an M-file that computes F, the values
of the equations at x.
function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
-x(1) + 2*x(2) - exp(-x(2))];
Next, call an optimization routine.
x0 = [-5; -5]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfun,x0,options) % Call optimizer"
So I made the following into an M file:
"function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
-x(1) + 2*x(2) - exp(-x(2))];
x0 = [-5; -5]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfun,x0,options) % Call optimizer"
When I try to run this code I get the error:
??? Input argument "x" is undefined.
Error in ==> fun1 at 3
F = [2*x(1) - x(2) - exp(-x(1));
Does anyone know what is wrong or how I can fix this problem? Any help would be great, thanks.