Using fsolve in simulink with a different equation each time

6 ビュー (過去 30 日間)
Tobias Dehn Nielsen
Tobias Dehn Nielsen 2022 年 10 月 3 日
コメント済み: Davide Masiello 2022 年 10 月 13 日
I have created this matlab scribt which solves the non-linear equation F with a given value of a. I would like to do the same in simulink. To solve the equation F for a given value of a. I have tried to use a interpreted matlab function but i can only change the initial guess not a value which is in the equation. Is it possible to do something similar in simulink?
function y = solve_theta_Be_to_theta_c(a)
y = fsolve(@(x)Function(x,a),[1]);
end
function F = Function(x,a)
l_1 = 75;
l_2 = 105;
l_3 = 450;
l_4x = 450;
l_4y = 110;
F = (l_4x + l_1 * cos(x) - l_3 * cos(a))^2 + (l_4y + l_3 * sin(a) - l_1 * sin(x))^2 - l_2^2;
end

採用された回答

Davide Masiello
Davide Masiello 2022 年 10 月 3 日
In Simulink, you can keep a as a generic parameter
syms x a
eqn = (450 + 75 * cos(x) - 450 * cos(a))^2 + (110 + 450 * sin(a) - 75* sin(x))^2 - 105^2 == 0;
S = solve(eqn)
S = 
Now that you have the solution, just give a a specific value and you get your answer
for a = 1:4
fprintf('--------------------------------------------------------------------------------\n')
fprintf('Solution for a = %d\n',a)
subs(S)
end
--------------------------------------------------------------------------------
Solution for a = 1
ans = 
--------------------------------------------------------------------------------
Solution for a = 2
ans = 
--------------------------------------------------------------------------------
Solution for a = 3
ans = 
--------------------------------------------------------------------------------
Solution for a = 4
ans = 
  2 件のコメント
Tobias Dehn Nielsen
Tobias Dehn Nielsen 2022 年 10 月 13 日
It worked! Thanks!
Davide Masiello
Davide Masiello 2022 年 10 月 13 日
My pleasure. If the answer helped, don't forget to Accept it!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by