MATLAB Answers

How do solve four variables with one equation using Runge-kutta?

조회 수: 1(최근 30일)
Jibeom Hong
Jibeom Hong 2021년 6월 10일
댓글: Jibeom Hong 2021년 6월 12일
h= 0.001;
tfinal = 0.2;
t(1)=0; v(1)=3.388; lc(1)=0; z(1)=0;
f=@(t,v,lc,z) (((0.015*log((sqrt(0.015+z)+sqrt(z))/0.015^(3/2))+sqrt(z)*sqrt(z+0.015)-z+2*0.015*log(0.015+lc))/(2*log(0.015+lc)-2*log(0.015)))*9.81*z-998*(9.81*lc-0.5*v^2)*2*pi*(0.015^2)+0.11*9.81)/(0.11-1.38*pi*(0.015^2)*998*(log((sqrt((z-lc)^2)/sqrt((0.015^2)+(z-lc)^2)))-0.015))
for i=1:ceil(tfinal / h)
k2=h*f(t(i)+0.5*h, v(i)+0.5*k1*h, lc(i)+0.5*k1*h, z(i)+0.5*k1*h);
k3=h*f(t(i)+0.5*h, v(i)+0.5*k2*h, lc(i)+0.5*k2*h, z(i)+0.5*k2*h);
k4=h*f(t(i)+h, v(i)+k3*h, lc(i)+k3*h, z(i)+k3*h);
% 1 eq, 4variables
%im matlab Beginner, this is my code. who can i help me....

채택된 답변

James Tursa
James Tursa 2021년 6월 11일
편집: James Tursa 2021년 6월 11일
You have three state variables, namely v, lc, and z. But you only have code for updating v. You need code for updating lc and z also. You have a couple of choices. Either have three function handles like this:
f=@(t,v,lc,z) (code for vdot here)
g=@(t,v,lc,z) (code for lcdot here)
h=@(t,v,lc,z) (code for zdot here)
Or you could create a single vector function handle to contain all three derivatives:
f=@(t,v,lc,z) [vdot;lcdot;zdot]
You would need to fill in the code for vdot, lcdot, and zdot. Looks like maybe the code you currently have for f only has the derivative for vdot, but you need all three.
Then you need to modify the code in your loop to handle these extra variables also. How you modify your looping code will depend on which choice you make for your derivative functions.

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by