フィルターのクリア

How to define variables in the main program instead of in the function file

2 ビュー (過去 30 日間)
I want to use a loop in the main program to make
a
the different value, and then get different graphics, but without defining
a
in the function file it can't run, how to solve, thank you!
codes are as this
function file
function f = rigid(t,y)
syms a
f = zeros(2,1); % a column vector
f(1) = a*y(2) * y(1);
f(2) = -y(1) * y(2);
main program
a=1;
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4]);
[T,Y] = ode45(@rigid,[0 12],[1 1],options);
plot(T,Y(:,1),'-',T,Y(:,2),'-.')

採用された回答

madhan ravi
madhan ravi 2019 年 8 月 3 日
function f = rigid(t,y,a)
% syms a %% not needed
f = zeros(2,1); % a column vector
f(1) = a*y(2) * y(1);
f(2) = -y(1) * y(2);
%-------
a=1;
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4]);
[T,Y] = ode45(@(t,y)rigid(t,y,a),[0 12],[1 1],options);
plot(T,Y(:,1),'-',T,Y(:,2),'-.')
  3 件のコメント
madhan ravi
madhan ravi 2019 年 8 月 3 日
編集済み: madhan ravi 2019 年 8 月 3 日
That was also an example you can change other parameters too , it's called parameterization see the link below:
for a = 1:10
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4]);
[T,Y] = ode45(@(t,y)rigid(t,y,a),[0 12],[1 1],options);
plot(T,Y(:,1),'-',T,Y(:,2),'-.')
end
dcydhb dcydhb
dcydhb dcydhb 2019 年 8 月 4 日
solve the problem and thanks a lot!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

タグ

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by