need help for euler code

I have an assignment for tomorrow and been strugling with it for a week. It roughly asks for the vertical position of a mass thrown upward while gravitational acceleration value is changing as x changes. When I put the value 1, it works well. However, it also requires to test input values different from 1 such as 0.1, 10, 100, and they does not work whatsoever. Anybody can help me to fix it?
function[delta] = projectile(tdelta) %first of all I have to construct a funtion.
v0=1800; %an arbitrary v0 value
h=tdelta; %I added this line just because not to get any error
g0=9.8; %gravitational acceleration
Radius=6370; %radius of earth in km
tmax = v0/g0; %this line supossed to be time elapsed until reach the possible max altitude
x=0; %x refers to altitude
for t=0:h:tmax %h value should be the time intervals for euler method.
x=x+h*(v0/1000 - g0*t*((1-h/Radius)^2))); %this part is the where pain starts.
% (v0/1000 - g0*t*((1-h/Radius)^2))) <-- this part is velocity, which is the derivative of x function. gravitational acceleration is changing also.
% g0(1-h/R) is basically gravitational acceleration due to altitude.
plot(t,x)
end

回答(0 个)

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by