Polt an object in uniform circular motion with Euler method
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi guys,
I have a little problem with a task that I have to solve. The task is described as follows here:
When I plot my code the points do not go into the negative range.
Here is my code and the plot:
clear
ac(1) = 0.5
xi(1) = 2
yi(1) = 0
xvi(1) = 0
yvi(1) = 1
t(1) = 0;
h = 0.1;
Vx(1) = ((-ac*xi(1)) / sqrt(xi(1)^2+yi(1)^2))*t(1)
Vy(1) = ((-ac*yi(1)) / sqrt(xi(1)^2+yi(1)^2))*t(1)+1
xstart = 1;
xend = 20;
xiter = (xend-xstart)/h;
for i=1:xiter
t(i+1) = t(i) + h;
xi(i+1) = xi(i) + h * Vx(i);
yi(i+1) = yi(i) + h * Vy(i);
Vx(i+1) = ((-ac*xi(i+1)) / sqrt(xi(i+1)^2+yi(i+1)^2))*t(i+1);
Vy(i+1) = ((-ac*yi(i+1)) / sqrt(xi(i+1)^2+yi(i+1)^2))*t(i+1)+1;
end
plot(xi,yi, '-bo')
title('Circular Euler Method')
xlabel('X')
ylabel('Y')
axis([-3 3 -3 3])
I think the result should look more like this:
Thanks in advance for your help!!
Greetings Lukas
0 comentarios
Respuestas (1)
James Tursa
el 20 de Oct. de 2022
Editada: James Tursa
el 20 de Oct. de 2022
So you have made a good start, but you have errors in your derivatives ... why do you have t's in your derivative equations? There are no t's in the derivative formulas you were given, so they shouldn't appear in your equations.
Also, you kind of have a hybrid method going on in your code. The positions use Euler's Method, but the velocity doesn't. I think the intent of the exercise is to use Euler's Method for everything.
The general code, using your code as an outline, would be something like this:
% In all the following code, PUT THE UNITS USED FOR ANY NUMBERS IN COMMENTS OFF TO THE RIGHT!
___ % Put code here for any constants
___ % Put code here for any fixed calculations, such as h, t_start, t_end, xiter, etc.
___ % Put code here to allocate your state variables xi, yi, Vx, Vy, and t
% Here is the code for initial conditions
t(1) = ___
xi(1) = ___
yi(1) = ___
Vx(1) = ___
Vy(1) = ___
% Now the Euler integration loop
for i=1:xiter
t(i+1) = t(i) + h;
xi(i+1) = xi(i) + h * Vx(i); % Euler step for xi
yi(i+1) = yi(i) + h * Vy(i); % Euler step for yi
Ax = ___ % you fill this in based on xi(i) and yi(i), NO t's!
Ay = ___ % you fill this in based on xi(i) and yi(i), NO t's!
Vx(i+1) = Vx(i) + h * Ax; % Euler step for Vx
Vy(i+1) = Vy(i) + h * Ay; % Euler step for Vy
end
Your job is to fill in the blanks above. The initial conditions are just the numbers you were given (but put the units in comments off to the side). The Ax and Ay are simply the formulas you were given based on the current x and y positions, which are xi(i) and yi(i). Note there are no t's in the Ax and Ay formulas. Acceleration is only dependent on position, not time.
0 comentarios
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!