How should i go about solving a set of ODEs for a set of data points? I would like to automate it as much as possible.

2 ビュー (過去 30 日間)
Currently I am using the ode45 solver, with my input parameters being a vector of length 7, which is two separate terms being length 6 and 1. My equations has a variable which needs to be solved for set amount of time and then it changes.
How do i go about doing this?
%so what im doing is,
tspan = [0 20];
options = odeset('MaxStep',0.05,'RelTol',1e-8,'AbsTol',1e-9);
stress1 = [525 450 385 200 150];
stress2 = [630 560 475 332 200];
for ii =1:length(stress1) % i intend to repeat this process for stress2
odeIp = [0 0 0 0 0 0 0 1 ii]';
odeOp = ode45(@odefn,tspan,odeIp,options);
Var2 = odeOp( : , 7); %gives me Solrequired
VarRequied(:,ii) = Var2;
end
%in the function im im using If statement to choose my initial conditions
function dOdeOp = odefn(t,odeIp)
%input constants and splitting the terms
stress1 = [525 450 385 200 150];
stress2 = [630 560 475 332 200];
D0 = odeIp(7,1);
alpha = odeIp(1:6);
var = odeIp(8,1);
sigvar = odeIp(9,1);
if var ==1
mSig = 0;
else
mSig = 100;
end
if var ==1
aSig = stress1(sigvar);
else
aSig = stress2(sigvar);
end
equat = mSig + aSig*sin(omega*t);
dequat = aSig*omega*cos(omega*t);
%solve set of equations outputs Sol1,SolRequired
% solving a bunc of equtions to get Sol1 which is an array of 1x6 and SolRequired
% which makes up the 7 column
dOdeOp1 =[Sol1;SolRequired];
dOdeOp2 = [dOdeOp1;var];
dOdeOp = [dOdeOp2;sigvar];
currently only the last two coulmns of my output vector is obtaining values, which shouldnt be the case

採用された回答

Jon
Jon 2019 年 8 月 19 日
Please see my earlier comments.
From the behavior you describe, it looks like Sol1 and SolRequired are returned empty from what ever solver produces them. In that case your last few lines of code would result in a dOdeOp that has only two elements (var and sigvar).
  5 件のコメント
Sajjan Gundmi Satish
Sajjan Gundmi Satish 2019 年 8 月 19 日
Thank You so much, this was very insightful.
Jon
Jon 2019 年 8 月 19 日
Glad it was helpful. Good luck with your project!

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

その他の回答 (1 件)

Jon
Jon 2019 年 8 月 19 日
編集済み: Jon 2019 年 8 月 19 日
I am not clear on the details of your implementation. It would take some time to go through it all line by line.
In case it is helpful though I noticed a couple of things that could be problematic.
I don't see where you ever use the values that you have assigned to the variable that you have named "variable". As a side point, it would make your code more understandable if you used a more descriptive name than "variable".
I don't see where you ever assign a value to Dataset1 and Dataset2
I don't see where you ever assign a value to SolRequired
The variables equat and dequat never seem to be used
  3 件のコメント
Jon
Jon 2019 年 8 月 19 日
So just to be clear, your problem is that values are only being assigned to the last two elements of odeOp?
If you could make a self contained example script that demonstrates the problem, then I can run then I might be able to step through and see what is wrong.
Even better, I would suggest that you single step through your code using the MATLAB debugging tools, and then you can see exactly what is happening. At each step you can see the values of the various variables, and also how it is following the branching logic. If you are not already familiar with how to use the MATLAB debugging tools, I highly recommend learning about them. Check out https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
Jon
Jon 2019 年 8 月 19 日
Sorry, I inadvertently opened up a second answer to this question rather than continuing the original thread. They both however go together.

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

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by