# Solving using ODE45

15 views (last 30 days)
Henry Jackson on 23 Sep 2020 at 19:26
Answered: Star Strider on 23 Sep 2020 at 20:44
I am new to matlab and have not been able to figure out this question. I have to use the function 'ode45' do derive dw/dt=a*w^(n)+b*w.
some info:
0<=t<=20
the initial value of w_0=0.2.
a=5.05
b=2
n=[0.60 0.62 0.64 0.66 0.68 0.70];
t1=[6.22 3.59 2.68 2.53 2.19 1.82];
the question asks to solve the equation using ode45 function (note that 0 ≤ t ≤ 20 and w_0 = 0.5 ) and and use the solution to find the time t1 that equals w_1=10
Here is the code I have, I know it is wrong but i thought I would just have it here.
n=[0.60 0.62 0.64 0.66 0.68 0.70];
t1=[6.22 3.59 2.68 2.53 2.19 1.82];
a=5.05;
b=2
w_0=0.5;
w_1=10;
ode@(t1,w)(a*w^(n)+b*w);
[t1,w]=ode45(@ode,[0:20],0.2);

Star Strider on 23 Sep 2020 at 20:44
I am not certain what you are doing.
One problem is that you would have to iterate over ‘n’ with a loop, because otherwise the ‘ode’ differential equation would not return the column vector it must in order to work with ode45.
Try this:
n=[0.60 0.62 0.64 0.66 0.68 0.70];
t1=[6.22 3.59 2.68 2.53 2.19 1.82];
a=5.05;
b=2;
w_0=0.5;
w_1=10;
ode = @(t1,w,n) (a*w.^(n)+b*w);
for k = 1:numel(n)
[t1,w(:,k)]=ode45(@(t,w) ode(t,w,n(k)),[0:0.1:20],0.2);
end
figure
plot(t1,w)
grid
xlim([0 1])
xlabel('t_1')
ylabel('w')
nstr = compose('n = %.2f',n);
legend(nstr, 'Location','NW')
Make appropriate changes to get the result you want.
I leave the determination of the time to get to ‘w_1=10’ to you.