Using MATLAB to do Numeric Calculus

조회 수: 4 (최근 30일)
Spaceman
Spaceman 2024년 4월 22일
댓글: Spaceman 2024년 4월 29일
So I am culminating all of my newfound knowledge to solve and show a simple calculus problem. However I am running into issues...
Given: A piecewise function where v(t)=70t @ t<=20s & 1596.2-9.81t @ 20<t<t_max <---(eq 1)
Also given: s(t)=35t^2+7620 @ t<=20s & 1596.2t-4.905t^2-8342 @ 20<t<=t_max <---(eq 2)
Find: If aircraft ignites its engines at t=0s and accelerates vertically, there is only enough fuel for an engine burn of 20 seconds. At which time will the ship become a projectile? Find value of t_max. Plot the crafts velocity vs. t, (eq 1). Plot the crafts altitude vs. t, (eq 2).
My Solution:
%% Finding Value of tmax
% Finding tmax and rounding it to the nearest whole number
%%
tmaxr=roots([-9.81, 1596.2]);
tmax=ceil(tmaxr);
%% Plotting Equation 1
% Creating Figure 1 from Equation 1
%%
t=0:0.1:tmax;
v=zeros(size(t));
for N=1:length(t)
if t(N)<=20
v(N)=70*t(N);
else
v(N)=1596.2-9.81*t(N); % Only valid for t > 20 seconds
end
end
figure(1)
plot(t,v)
xlabel('Time (s)')
ylabel('Velocity (m/s)')
title('Velocity vs. Time')
%% Plotting Equation 2
% Creating Figure 2 from Equation 2
%%
t=0:0.1:tmax;
s=zeros(size(t));
for N=1:length(t)
if t(N)<=20
s(N)=35.*t(N).^2+7620;
else
s(N)=1596.2.*t(N)-4.905.*t(N).^2-8342;
end
end
figure(2)
plot(t,s)
xlabel('Time (s)')
ylabel('Altitude (m)')
title('Position vs. Time')
Issue: So I have found t_max, plotted the velocity but it looks funky, and also tried to plot my altitide but not sure if it's faultless.
P.s. Sorry for the formatting, there's no easy way to type piecewise functions that I know of.

채택된 답변

Torsten
Torsten 2024년 4월 22일
편집: Torsten 2024년 4월 22일
Your code is correct.
Here is a simpler way to define s and v. Just substitute tcrash by tmax.
tcrash = 1596.2/(2*4.905)+sqrt((1596.2/(2*4.905))^2-8342/4.905);
s = @(t)(35*t.^2+7620).*(t<=20)+(1596.2*t-4.905*t.^2-8342).*(t>20).*(t<=tcrash);
v = @(t)(70*t).*(t<=20)+ (1596.2-9.81*t).*(t>20).*(t<=tcrash);
t = 0:0.01:tcrash;
figure(1)
plot(t,s(t))
grid on
figure(2)
plot(t,v(t))
grid on
  댓글 수: 6
Sam Chak
Sam Chak 2024년 4월 24일
I suppose @Kyle intended to estimate the rate of change based on the simulated data points, rather than directly from the kinematic equation. Observing the curve, it appears that the aircraft (modeled as a point mass) is descending rapidly towards the ground. Is this behavior intentional and meant to be displayed?
Spaceman
Spaceman 2024년 4월 29일
I was examining the kinematic equations to plot the information and compare it to the derivative approximation of velocity, etc. I was then plotting the integral approximation and comparing it to the past plots. I got it all figured out, though. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by