0% found this document useful (0 votes)
75 views4 pages

Code Ode45

This document contains code to simulate 1D heat transfer using the ode45 solver in MATLAB. It defines a function called mydiff that calculates the rate of change of temperature at interior points in a 1D rod with boundary conditions of 40 degrees at one end and 70 degrees at the other. It then calls ode45 to solve the ODE and plots the temperature over time at the boundaries.

Uploaded by

Tấn Phạm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views4 pages

Code Ode45

This document contains code to simulate 1D heat transfer using the ode45 solver in MATLAB. It defines a function called mydiff that calculates the rate of change of temperature at interior points in a 1D rod with boundary conditions of 40 degrees at one end and 70 degrees at the other. It then calls ode45 to solve the ODE and plots the temperature over time at the boundaries.

Uploaded by

Tấn Phạm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

function heat_1D_ode45()

L=1;

NX=100;

dx=L/NX;

T0=zeros(NX+1,1)+5;

x=linspace(0,L,NX+1);

T0(1)=40;

T0(NX+1)=70;

[t,y] = ode45(@mydiff,[0 0.01],T0)

plot(x,y(1,:),'-o',x,y(end,:),'-o')

title('Solution with ODE45');

xlabel('Time t');

ylabel('Solution y');

legend('y_1','y_2')

function dydt=mydiff(t,y)

T=y;

dydt=zeros(NX+1,1);

for i=2:NX %2-99

dydt(i)=(T(i+1)-2*T(i)+T(i-1))/dx/dx;

end
end

end
function particle_falling_3()

[t,y] = ode45(@FF,[0 3.18],[0.1 ; 0])

plot(t,y(:,1),'-o',t,y(:,2),'-o')

title('Solution with ODE45');

xlabel('Time t');

ylabel('Solution y');

legend('y_1','y_2')

Re_partical=Re_p

function dydt=FF(t,y)

g=9.80655;

va=0;

Dp=1.6;

rho=1.166;

rho_p=1220;

muy=1.870264E-5;

v=y(1);

s=y(2);

Re_p=rho*Dp*(v+va)/muy;

V=1/6*pi*Dp^3;

if Re_p<2
C_D=24/Re_p;

elseif Re_p<500

C_D=18.5/Re_p^0.6;

else

C_D=0.44;

end

dvdt=(V*(rho_p-rho)*g-C_D*pi*Dp^2/4*rho*(v+va)^2/2)/(V*rho_p);

dsdt=v;

dydt=[dvdt;dsdt];

end

end

You might also like