Solving using ODE45

조회 수: 4 (최근 30일)
Henry Jackson
Henry Jackson 2020년 9월 23일
답변: Star Strider 2020년 9월 23일
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
Star Strider 2020년 9월 23일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by