MATLAB question please help! Piecewise functions are sometimes use…
MATLAB question please help!
Piecewise functions are sometimes useful when the relationship between a dependent and an independent variable cannot be adequately represented by a single equation. For example, the velocity of a rocket might be described by
Develop an M-file function to compute v as a function of t. Then, use this function to generate a plot of v versus t for t = ?5 to 50
Click the button below to view answer!
Technifi Expert’s Answer:
% Generate the time values % Calculate t values with step 1 in the range 0<=t<=10 t1Step1 = 0:1:10; % Calculate t values with step 0.5 in the range 0<=t<=10 t1StepPoint5 = 0:0.5:10; % Calculate t values with step 1 in the range 10<t<=20 t2Step1 = 11:1:20; % Calculate t values with step 0.5 in the range 10<t<=20 t2StepPoint5 = 10.5:0.5:20; % Question 1 % Calculate velocity upto 10 with step 1 v1=11.*((t1Step1).^2)-5.*(t1Step1); % Calculate veloity from 11 to 20 and append the previous output v1=[v1 1100-5.*t2Step1]; % Question 2 % Calculate velocity upto 10 with step 0.5 v2=11.*((t1StepPoint5).^2)-5.*(t1StepPoint5); % Calculate veloity from 10.5 to 20 and append the previous output v2=[v2 1100-5.*t2StepPoint5]; % Question 3 % Tabulate velocity with step 1 tabulate1=[0:20;v1]; % Tabulate velocity with step 0.5 tabulate2=[0:0.5:20;v2]; % Question 4 % Plot with step 1 subplot(2,1,1) plot(0:20,v1) title('Velocity with Step 1') % Plot with step 0.5 subplot(2,1,2) plot(0:0.5:20,v2) title('Velocity with Step 0.5')
If you happen to run into some problem while following the steps, please make sure to let us know in the comment section below, and we’ll do our best to solve it. Apart from that, you can contact us on Facebook and Twitter, however we can’t guarantee a rapid reaction time over those platform