Shooting method ode45 Fzero

20 次查看(过去 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