Quantcast
Channel: MATLAB Central Newsreader - tag:"variables"
Viewing all articles
Browse latest Browse all 41

using fsolve returns initial values

$
0
0
Dear all,

I'm trying fsolve to solve a nonlinear system comprising of 4 equations.
The function that I declared looks like this:
%%%%%%%%%%
function F = myfun( y )
%y is the solution vector (xx zz zeta1 eta1)

F=[y(4)-A2*sinh(2*k*(d+eta2i))/sinh(2*k*d)*cos(2*k*zeta2i)-B2-eta2i;
    y(1)-A1*cosh(k*(d+y(4)))/sinh(k*d)*sin(k*y(3))-y(3);
    y(2)-A1*sinh(k*(d+y(4)))/sinh(k*d)*cos(k*y(3))-y(4);
    y(3)-A2*cosh(2*k*(d+ea2i))/sinh(2*k*d)*sin(2*k*zeta2i)-zeta2i];
%%%%%%%%
All variables are declared global and there are only four unknown variables. Vector y is the solution vector and supposed to give the four values xx zz zeta1 and eta1.

Now, I'm using the following code to call the function.
The loop is used to make the calculation for 120 times.
%%%%%%%%%%%%
x00=[1;1;1;1]; % Make a starting guess at the solution
for i=1:120
   global eta2i
   eta2i=eta(i);
   global zeta2i;
   zeta2i=vector(i)

   options = optimoptions('fsolve','Display','iter'); % Option to display output
   [y,fval] = fsolve(@TransformZetaAndEta,x00,options); % Call solver
   xx(i)=y(1);%y is vector (xx zz zeta1 eta1)
   zz(i)=y(2);
   zeta1(i)=y(3);
   eta1(i)=y(4);
end
%%%%%
However, when I have a look at the solution, the vectors xx, zz, zeta1 and eta1 are all the initial values, i.e. 1. Changing the initial value-vector x00 doesn't make any difference. However, these values can't be valid or a true solution to the problem (I tried to make a calculation using these values which results in error messages).

I would very appreciate any help or hint to this problem.

Kind regards and thanks in advance
Magnus

Viewing all articles
Browse latest Browse all 41

Trending Articles