필터 지우기
필터 지우기

How to get values at different interval for ode45

조회 수: 5 (최근 30일)
Mayokun  Ojediran
Mayokun Ojediran 2019년 9월 18일
댓글: darova 2019년 9월 18일
Hello,
I solved a second order differential equation with ode45, the code ran smoothly.
I want to extract the value of the results at different intervals 0:0.1:1.
Is there a way to this in Matlab?
function Shooting_Method
clc;clf;clear;
global C__T R__D S__h Q gamma beta P__e
C__T=0.1;
R__D=0.3;
S__h = 0.1;
Q = 0.4;
gamma = 0.1;
beta = 0.2;
P__e = 1;
x=0.5;
x1=fzero(@solver,x)
end
function F=solver(x)
options=odeset('RelTol', 1e-9, 'AbsTol', [1e-9 1e-9], 'OutputFcn', @odeplot);
[t,u] = ode45(@equation, [0 1], [x,0], options);
s=length(t);
F=u(s,1)-1;
figure(1)
plot(t,u(:,1))
end
function dy = equation(t,y)
global C__T R__D S__h Q gamma beta P__e
dy=zeros(2,1);
dy(1) = y(2);
dy(2) = ((4 * C__T ^ 3 * y(1) * R__D) + (6 * C__T ^ 2 * R__D * y(1) ^ 2)+...
(4 * C__T * R__D * y(1) ^ 3) + (y(1) ^ 4 * R__D) - S__h * Q * gamma...
* y(1) - beta * y(2) ^ 2 + S__h * (y(1) ^ 2) + P__e * y(2) - S__h * Q)...
/ (beta * y(1) + 0.1e1);
end

답변 (1개)

darova
darova 2019년 9월 18일
Use for loop to get results for x = 0: 0.1: 1 (11 curves)
hold on
for x = 0:0.1:1
[t,u] = ode45(@equation, [0 1], [x 0])
plot(t,u(:,1))
end
hold off
  댓글 수: 2
Mayokun  Ojediran
Mayokun Ojediran 2019년 9월 18일
@darova I am not trying to solve for different values of x, I am trying to display the results for u for different values of t. Thank you
darova
darova 2019년 9월 18일
There two ways to do this
First one
tspan = 0:0.1:1;
[t,u] = ode45(@equation, tspan, [x 0])
plot(t,u(:,1))
Second one
[t,u] = ode45(@equation, [0 1], [x 0])
t1 = 0:0.1:1;
u1 = interp1(t,u(:,1),t1);
plot(t,u(:,1)) % ode45 data
hold on
plot(t1,u1,'.r') % data at specific points
hold off

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by