when I saved the m-file below under the name trial.m
function fcns=trial(z)x=z(1);y=z(2);fcns(1)=A.*x.^p1+2.*y.^2-5.*x+7.*y-40;fcns(2)=3.*x.^2-y.^2+4.*x+B.*y.^p2-28;end
and when I entered in the command window:
A=1B=2p1=2p2=1guess=[2 3]
and after that I entered in the command window:
result=fsolve(@trial,guess)
I received the following error message:
??? Undefined function or variable 'A'.Error in ==> trial at 4fcns(1)=A.*x.^p1+2.*y.^2-5.*x+7.*y-40;Error in ==> fsolve at 254fuser = feval(funfcn{3},x,varargin{:});Caused by:Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
Please what is wrong in my m-file ? ( the same m-file is working when A,B,p1 and p2 are replaced by numbers in the m-file )
I am using m-files like this one because working with x and y for me is easier than working with other names of variables.
Also the m-file must have a name because I need it to use it when I am entering the f-solve command in the command window.
Best Answer