Fluid Pathline using Euler's Method with MATLAB
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kristjan Gjata
le 20 Mar 2021
Modifié(e) : Alan Stevens
le 21 Mar 2021
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 commentaires
Réponse acceptée
Alan Stevens
le 21 Mar 2021
Modifié(e) : Alan Stevens
le 21 Mar 2021
Replace
t1=t0+h;
by
t0=t0+h;
or add a line
t0 = t1;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linearization Basics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!