4 views (last 30 days)

Hello,

I have to resolve a system with 8 equations and 8 unknows and I'm using Fsolve to do it. The problem is that the results isn't the awaited (I have the numerical solution).

Can it maybe depend on the trigonometric function?

What's my wrong?

Thank you in advance.

sol =fsolve(@(x)funzmia2(x), 1:8);

XA1=sol(1);

YA1=sol(2);

XB1=sol(3);

YB1=sol(4);

T12=sol(5);

T13=sol(6);

T14=sol(7);

T15=sol(8);

function G=funzmia2(x)

XA1=x(1);

YA1=x(2);

XB1=x(3);

YB1=x(4);

T12=x(5);

T13=x(6);

T14=x(7);

T15=x(8);

XA0=2.1;

YA0=0.6;

XB0=1.5;

YB0=4.2;

x1=1;

y1=1;

x=[2,3,2,1.5];

y=[0.5,1.5,2,1.9];

G(1)=XA1*XA0+YA1*YA0-x(1)*XA0-y(1)*YA0-x1*XA1-y1*YA1+(x1^2+y1^2+x(1)^2+y(1)^2)/2+cos(T12)*(-XA1*XA0-YA1*YA0+x1*XA0+y1*YA0-x1*x(1)-y1*y(1)+x(1)*XA1+y(1)*YA1)+sin(T12)*(XA0*YA1-YA0*XA1-y1*XA0+x1*YA0+x(1)*y1-x1*y(1)+y(1)*XA1-x(1)*YA1);

G(2)=XA1*XA0+YA1*YA0-x(2)*XA0-y(2)*YA0-x1*XA1-y1*YA1+(x1^2+y1^2+x(2)^2+y(2)^2)/2+cos(T13)*(-XA1*XA0-YA1*YA0+x1*XA0+y1*YA0-x1*x(2)-y1*y(2)+x(2)*XA1+y(2)*YA1)+sin(T13)*(XA0*YA1-YA0*XA1-y1*XA0+x1*YA0+x(2)*y1-x1*y(2)+y(2)*XA1-x(2)*YA1);

G(3)=XA1*XA0+YA1*YA0-x(3)*XA0-y(3)*YA0-x1*XA1-y1*YA1+(x1^2+y1^2+x(3)^2+y(3)^2)/2+cos(T14)*(-XA1*XA0-YA1*YA0+x1*XA0+y1*YA0-x1*x(3)-y1*y(3)+x(3)*XA1+y(3)*YA1)+sin(T14)*(XA0*YA1-YA0*XA1-y1*XA0+x1*YA0+x(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2+cos(T15)*(-XB1*XB0-YB1*YB0+x1*XB0+y1*YB0-x1*x(4)-y1*y(4)+x(4)*XB1+y(4)*YB1)+sin(T15)*(XB0*YB1-YB0*XB1-y1*XB0+x1*YB0+x(4)*y1-x1*y(4)+y(4)*XB1-x(4)*YB1);

end

Are Mjaavatten
on 22 Jan 2020

Edited: Are Mjaavatten
on 22 Jan 2020

Your function has several different zeros. Which one fsolve finds will depend on the starting point. I ran:

f = 100; while norm(f)>1e-5;x0 = randn(1,8);x = fsolve(@funzmia2,x0);f = funzmia2(x); end;x

a few times and came up with these solutions:

x =

0.6074 -1.1271 -0.5864 0.9970 -0.0239 0.7690 1.5855 1.9381

x =

0.8133 -1.3517 3.0430 -0.0529 3.8244 0.5740 -1.1023 -0.7352

x =

1.3195 0.4235 -4.7913 10.3315 -1.2170 -0.7230 -0.1282 -0.2885

x =

1.4074 0.3822 -18.0967 27.4654 0.3974 -0.8546 -0.2216 -0.3651

To find the solution you seek, say xstar, you should set x0 to be not too different from xstar.

Are Mjaavatten
on 23 Jan 2020

The simplest way to find an x0 that gives your solution is probably to run the code in my previous comment until you get the solution you seek. Then you know that starting with the current x0 will converge to the sought soltion.

By the way: What makes this solution "better" than the others? If there are bounds on your variables (e.g. all elements of x must be positive) you should try another approach. Take a look at this page. Alternatively, you might try my broyden function. This is less robust than fsolve, but the formulation of bounds is quite straight-forward.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788792

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788792

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788805

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788805

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788829

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788829

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788837

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788837

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788850

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788850

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788872

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788872

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788880

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_788880

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_789155

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/501491-fsolve-don-t-work-good-with-trigonometric#comment_789155

Sign in to comment.