Loop in solve system of nonlinear equations

2 ビュー (過去 30 日間)
Krystian Fornal
Krystian Fornal 2019 年 10 月 17 日
コメント済み: Krystian Fornal 2019 年 10 月 17 日
I have a problem with loop "for" in Solve system of nonlinear equations. I can solve nonlinear equations like this:
R=68.4043297;
V = [teta1; teta2];
F = @(V) [R-(37.5*sqrt(3))+(75*cos(V(1)))-(75*cos(V(2))); 97.5+37.5+(75*sin(V(1))) - (54.4818+75*sin(V(2)))];
XYA= fsolve(F, InitialGuess, Options);
but I have to change parametr R.
R=45:0.1:95
How do it?

回答 (1 件)

Wiley Mosley
Wiley Mosley 2019 年 10 月 17 日
By calling the index of R in the for loop you should be able to save the XYA in an array so that you have the solutions for all values of R.
R=45:0.1:95;
for ii = 1:numel(R);
V = [teta1; teta2];
F = @(V) [R(ii)-(37.5*sqrt(3))+(75*cos(V(1)))-(75*cos(V(2))); 97.5+37.5+(75*sin(V(1))) - (54.4818+75*sin(V(2)))];
XYA(ii)= fsolve(F, InitialGuess, Options);
end
  2 件のコメント
Krystian Fornal
Krystian Fornal 2019 年 10 月 17 日
But I get this:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Untitled3 (line 5)
XYA(ii)= fsolve(F, InitialGuess, Options);
Krystian Fornal
Krystian Fornal 2019 年 10 月 17 日
But now i've got a solution:
R=linspace(45,95,11);
for i=1:11
V = [teta1; teta2];
F = @(V) [R(1,i)-(37.5*sqrt(3))+(75*cos(V(1)))-(75*cos(V(2))); 97.5+37.5+(75*sin(V(1))) - (54.4818+75*sin(V(2)))];
InitialGuess = [2;2];
Options=optimset('Display','off');
XY(2:3,i)= fsolve(F, InitialGuess, Options);
XY(1,i)=R(1,i);
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTransfer Function Models についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by