# How to run ode15s function for several times

3 views (last 30 days)
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:
eq1=diff(uc(t),2)==(-1/(L*(3*mc+4*h2*L*pi*a2*Ro)))*(3*(-Ft*L+4*h2*pi*a11*a2*(uc(t)+Beta*diff(uc(t)))+L*(alfa*mc*diff(uc(t))+pi*(p2(t)*a2^(2)-p1(t)*a2^(2)+2*h2*a12*(wr1(t)-wr2(t)+Beta*diff(wr1(t))-Beta*diff(wr2(t))))))+4*pi*h2*L^(2)*a2*alfa*Ro*diff(uc(t)));
eq2=(h2*L*a2^(2)*Ro)*diff(wr1(t),2)==(-h2*a12*a2*(uc(t)+Beta*diff(uc(t)))+L*(a2^(2)*p1(t)-h2*a22*(wr1(t)+Beta*diff(wr1(t))))-h2*L*a2^(2)*alfa*Ro*diff(wr1(t)));
eq3=(h2*L*a2^(2)*Ro)*diff(wr2(t),2)==(h2*a12*a2*(uc(t)+Beta*diff(uc(t))+L*(a2^(2)*p2(t)-h2*a22*(wr2(t)+Beta*diff(wr2(t)))))-h2*L*a2^(2)*alfa*Ro*diff(wr2(t)));
eq4=(pi*(L+uc(t))*(a1+wr1(t))^(2))*diff(p1(t))==(p1(t)-Bef)*((CD*Av*sqrt(2*(Bef-p1(t))*(p1(t)-p2(t))/(Bef*Rflu)))+pi*diff(uc(t))*(a2+wr1(t))^(2)+2*pi*(L+uc(t))*(a2+wr1(t))*diff(wr1(t)));
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.
##### 2 CommentsShowHide 1 older comment
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:
t=0
fo=10
w=5000
for i=1:1:100
if (t<=0.63e-3)
f=fo*sin(w*t);
else
f=0;
end
T(i)=t;
Ft(i)=f
t=t+0.00001
end
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);
t1=0:1e-4:1e-3;
t2=t1+1e-6;
[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

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.
##### 2 CommentsShowHide 1 older comment
Steven Lord on 14 Nov 2017
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.