Shooting method ode45 Fzero

20 views (last 30 days)
Jesper
Jesper on 12 Nov 2022
Edited: Torsten on 13 Nov 2022
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

Accepted Answer

Torsten
Torsten on 13 Nov 2022
Edited: Torsten on 13 Nov 2022
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

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!