Shooting method ode45 Fzero

조회 수: 21 (최근 30일)
Jesper
Jesper 2022년 11월 12일
편집: Torsten 2022년 11월 13일
I want to use the fzero function to approximate the value of t=1.65. However since the value of that point is about 501 and not zero, i am confused as how to code it. I am open to any solution as long as it uses the fzero function.
function shooting_method
x=1;
x1=fzero(@solver,x)
end
function F=solver(x)
% Parameters
L=3.6; %Length of stick
T0=315; % Temperature at x=0
TL=445; % temperature at x=L
options=odeset(RelTol=10^-6,AbsTol=10^-6);
[t,u]=ode45(@equation,[0 L],[T0 x],options);
s=length(t);
F=u(s,1)-TL;
figure(1)
plot(t,u(:,1))
end
function dy=equation(t,y)
L=3.6; %Length of stick
dy=zeros(2,1);
dy(1)=y(2);
dy(2)=((280*exp(-((t-L/2)^2))+y(2)/3)/(-(2+t/3)));
end

채택된 답변

Torsten
Torsten 2022년 11월 13일
편집: Torsten 2022년 11월 13일
Your code tries to determine dT/dt at t=0 such that the solution of the equation
d^2T/dt^2 = ((280*exp(-((t-L/2)^2))+(dT/dt)/3)/(-(2+t/3)))
T(0) = 315
passes through
T(L) = 445
and gets
dT/dt @(t=0) = 156
as solution.
L=3.6; %Length of stick
T0=315; % Temperature at x=0
TL=445; % temperature at x=L
x=1;
flag = 0;
x1=fzero(@(x)solver(x,flag,L,T0,TL),x)
x1 = 156.5218
flag = 1;
solver(x1,flag,L,T0,TL)
ans = 5.6843e-14
function F=solver(x,flag,L,T0,TL)
options=odeset(RelTol=10^-6,AbsTol=10^-6);
[t,u]=ode45(@(t,y)equation(t,y,L),[0 L],[T0 x],options);
s=length(t);
F=u(s,1)-TL;
if flag==1
plot(t,u(:,1))
end
end
function dy=equation(t,y,L)
dy=zeros(2,1);
dy(1)=y(2);
dy(2)=((280*exp(-((t-L/2)^2))+y(2)/3)/(-(2+t/3)));
end

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by