MATLAB Answers

How to run ode15s function for several times

3 views (last 30 days)
tamara hussien
tamara hussien on 13 Nov 2017
Commented: Steven Lord on 14 Nov 2017
Thanks for taking the time to read this, I am new to matlab. The following four equations are what I need to solve them by ode15s:
where uc,wr1,wr2,p1,p2 are state variables and mc,av Ft and t1 are fixed variables , all the other parameters are constant.
My problem is in the value of Ft=fo* sin(5000*t), for (t=0:0.63)sec then Ft=0 for (t=0.63:1)sec as a result for small increments I have 100 values of Ft and t1
I need to run my ode15s script 100 times for all 100 values of Ft and t1 then plot them in a single plot.
tamara hussien
tamara hussien on 13 Nov 2017
Thank you Mr.Jan Simon for asking about my problem. The problem occurs when I'm making a loop as follow:
for i=1:1:100
if (t<=0.63e-3)
now when I call my function handle as
Q = @(t, y) f(t, y, Ft, Av, mc)
y0est = [0; 0; 0; 0; 0; 0; 0; 0]; % initial values y0=[uc,wr1,wr2,p1,p2,uc",wr1",wr2"]
yp0est = zeros(8,1);
opt = odeset('Mass', M, 'InitialSlope', yp0est,...
'RelTol', 10.0^(-6), 'AbsTol' , 10.0^(-6));
implicitDAE = @(t,y,yp) M(t,y)*yp - Q(t,y);
[y0, yp0] = decic(implicitDAE, 0, y0est, [], yp0est, [], opt);
opt = odeset(opt, 'InitialSlope', yp0);
[tSol,ySol] = ode15s(Q, [t1 t2], y0, opt)
% y is vector of all state variables, t is time, Ft,Av,and mc are fixed variables.
here I can solve it for only one value of Ft and t1 when I'm writing it as Q(i)= @(t, y) f(t, y, Ft(i), Av, mc) the matlab gives me the error as "Dimensions of matrices being concatenated are not consistent." If possible please give me your email address, then I will attach to you my matlab code, because it is to much i can't write it here. Best regards

Sign in to comment.

Answers (1)

Yogananda Jeppu
Yogananda Jeppu on 13 Nov 2017
Try a simple Euler integration. Xd = f(a,b,c ...). x = Xd*dt+x; store the values of x in an array. See if this works.
Steven Lord
Steven Lord on 14 Nov 2017
tamara hussien had flagged this answer as "Good idea".
The purpose of flagging in the MATLAB Answers help is:
"A flag is a request for review that any contributor can assign to content. Contributors with sufficient privileges can then review and potentially revise, close, or delete the flagged content.
Questions, answers, and comments can be flagged if unclear, not appropriate, or spam."
Since you seem happy with the suggestion, I'm going to remove the flag.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!