Fluid Pathline using Euler's Method with MATLAB

Hello.
I'm trying solve a problem of my course lecture in Fluid Mechanics.
We have velocity: u = y^2 - x^2 + t^2 at X-direction and v= 2xy + 20t at Y-direction.
To find the pathline of fluid we have the initial conditions that x0=1.5, y0=1 and t0=0 and we should use Euler's Method to determine the function.
I use the step of 0.001 for the time variable until t(final) = 10.
The problem in below program is debugging. Can someone help me ?
clear all
clc
f=@(x,y,t)y^2-x*2+t^2;
g=@(x,y,t)2*x*y + 20*t;
x0=input('\n Enter initial value of x i.e. x0: ');
y0=input('\n Enter initial value of y i.e. y0: ');
t0=input('\n Enter initial value of t i.e. t0: ');
tn=input('\n Enter the final value of t: ');
h=input('\n Enter the step length h: '); %example h=0.001
%Formula: y1=y0+h*function(x0,y0,t0);
fprintf('\n t x y');
while t0<=tn
fprintf('\n%4.3f %4.3f %4.3g',t0,x0,y0); %values of t and x and y
x1=x0+h*f(x0,y0,t0);
y1=y0+h*g(x0,y0,t0);
t1=t0+h;
x0=x1;
y0=y1;
end
Thank you very much.

 采纳的回答

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Linearization Basics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by