how to use fsolve in for loop?

2 ビュー (過去 30 日間)
Luqman Alabri
Luqman Alabri 2021 年 5 月 20 日
コメント済み: Luqman Alabri 2021 年 5 月 21 日
I need to pass different values of (theta_r) into F(1) and F(2) to get different values of x(1) and x(2).
i use this code, but it shows me many errors.
clear all;
%defining the parameters.
global R L3 L4 L5 theta_r
R=80; L5=360; L4=360; L3=120; n=2; m=100*n;
theta_r=linspace(0,2*pi*n,m);
function F = value(x,theta_r)
F(1)=R*sin(theta_r)+L3*sin(x(1))-L5*sin(x(2));
F(2)= R*cos(theta_r)+L3*cos(x(1))-L5*cos(x(2))-L4;
end
for b = 1:numl(theta_r)
x(b,:)=fsolve(@(x)value(x,theta_r(b),[1,0]));
end
  1 件のコメント
Luqman Alabri
Luqman Alabri 2021 年 5 月 20 日
How can I fix this?

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

採用された回答

Jan
Jan 2021 年 5 月 20 日
編集済み: Jan 2021 年 5 月 21 日
global R L3 L4 L5
R=80; L5=360; L4=360; L3=120; n=2; m=100*n;
theta_r=linspace(0,2*pi*n,m);
for b = 1:numel(theta_r) % fixed: "numl"
x(b,:) = fsolve(@(x) value(x, theta_r(b)), [1,0]);
end
function F = value(x,theta_r)
global R L3 L4 L5
F(1)=R*sin(theta_r)+L3*sin(x(1))-L5*sin(x(2));
F(2)= R*cos(theta_r)+L3*cos(x(1))-L5*cos(x(2))-L4;
end
  5 件のコメント
Jan
Jan 2021 年 5 月 21 日
@Torsten: A good idea.
Luqman Alabri
Luqman Alabri 2021 年 5 月 21 日
Thank you all.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by