Euler's Method
조회 수: 5 (최근 30일)
이전 댓글 표시
I'm trying to solve the following problem by the Euler Method:
A parachutist of mass 68.1 kg jumps out of a stationary hot air balloon. Use Eq. (1.10) to compute velocity prior to opening the chute. The drag coefficient is equal to 12.5 kg/s.
The book gives me already the equation which is:
v=53.44(1-e^-0.18355*t)
I understand that mi initial values are:
x(0)=0
y(0)=0
h=2
x(f)=12
where x is t and y is v.
The table below are the answers but my code doesn't give me that solution.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/505888/image.png)
The answers i get by my code:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/505893/image.png)
MY CODE
clear all
clc
f=@(x,y) 53.44*(1-exp(-0.1835*x)); %Write your f(x,y) function, where dy/dx=f(x,y), x(x0)=y0.
x0=input('\n Enter initial value of x i.e. x0: '); %example x0=0
y0=input('\n Enter initial value of y i.e. y0: '); %example y0=0.5
xn=input('\n Enter the final value of x: ');% where we need to find the value of y
%example x=2
h=input('\n Enter the step length h: '); %example h=0.2
%Formula: y1=y0+h*fun(x0,y0);
fprintf('\n x y ');
while x0<=xn
fprintf('\n%4.3f %4.3f ',x0,y0); %values of x and y
y1=y0+h*f(x0,y0);
x1=x0+h;
x0=x1;
y0=y1;
end
댓글 수: 0
답변 (1개)
Alan Stevens
2021년 2월 1일
Since you are given velocity as a function of time, why don't you simply plug the desired values of time directly into the function?
vel = @(t) 53.44*(1 - exp(-0.18355*t));
t = [0; 2; 4; 6; 8; 10; 12; inf];
v = vel(t);
disp([t v])
Your function is a velocity, not a rate of change of velocity with time, so your statement
y1=y0+h*f(x0,y0);
doesn't result in a velocity, but a distance (though your timestep is probably too big for an accurate result).
댓글 수: 4
Alan Stevens
2021년 2월 1일
편집: Alan Stevens
2021년 2월 2일
To use Euler's method to calcuate veocities here, you need an acceleration (which you can get by differentiating the velocity function with respect to time). So, then your integration routine would look something like:
t = 0;
v = 0;
while t <= tfinal
v = v + h*acc(t);
t = t + h;
end
where acc is your acceleration function and h is your timestep size (I'd suggest using a much smaller value than 2 to get reasonably accurate resuts).
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!