From: rabbahs on
Hi all,

i am trying to solve a system of linear/nonlinear equations using fsolve command in matlab. But i am getting some undesirable results.

First of all, kindly look at the code.

function F=myfun(X,c1)

a=X(1);
b=X(2);
c=X(3);
d=X(4);
e=X(5);
f=X(6);
g=X(7);
p=X(8);

F(1)=a+b+d+g-c1(4);
F(2)=c1(6)+2*c1(7)+c1(8)-2*a-b-f;
F(3)=c1(5)+2*c1(8)-2*c-4*d-2*f;
F(4)=3.76*c1(7)-e;
F(5)=c1(1)*a*p-(b*b);
F(6)=c1(2)*f*p-(b*c);
F(7)=c1(3)*c*c-(d*p);
F(8)=a+b+c+d+e+f-p;

as u can see from above function script, i have 8 unknowns (i.e a,b,c,d,e,f,g & p).
c1(1) to c1(8) are constant (having value greater then 0)

the fsolve command which i am using to solve the above function is,

fsolve(@(X) myfun_1(X,[q r s m x y z k]),[1 1 1 1 1 1 1 1],options);

where,
myfun_1 is function file name
q r s m x y z k are constant c1(1) to c1(8) (all greater than zero)
options = optimset('MaxFunEvals',3000,'MaxIter',20000);
[11111111] are initial guess

the problems i am facing with this code are,

1) most of the time the solution is not converged
it gives me msgs like, change the initial guess ( which i changed thousands of time.)
it ask me to increase the MaxFunEvals and iteration (it tried it to up to millions)

2) I am expecting values from this code between 0-5 for the variable (surely greater than zero) but it is giving me negative results.

so is some thing wrong with my code ?
is there any cure for it ?

kindly let me know any possible solution for this problem, if any other information is required then kindly let me know.

thanks and regard

have a nice day

bye.
 | 
Pages: 1
Prev: ECG and Matlab
Next: MATLAB compiler