Question

0sts10 1100-5t 10<ts20 Write a matlab code to calculate velocity v at: v(t) = 1. step size of time 1 s 2. step size of time-0.5 s 3. tabulate values 4. plot both


0 0
Add a comment Improve this question Transcribed image text
Answer #1
Matlab Code

clc
clear all
close all

% Defining the step sizes
step_size1 = 1;
step_size2 = 0.5;

% Getting the time values of respective step sizes
t1 = 0 : step_size1 : 20;
t2 = 0 : step_size2 : 20;

% Preallocating the velcity points with zeros
vt1 = zeros(1, numel(t1));
vt2 = zeros(1, numel(t2));

% Calculating the velocity points with step size = 1s of time
k = 1;
fprintf('\n *** Step size = 1 s ***\n');
fprintf('\nTime (s)\tVelocity (m/s)\n\n');
for ii = 1:numel(t1)
if ii >= 0 && ii <= 10 % for 1st condition in limit
vt1(1, k) = 11 * t1(ii) * t1(ii) - 5 * t1(ii);
elseif ii > 10 && ii <= 20 % for 2nd condition in limit
vt1(1, k) = 1100 - 5 * t1(ii);
end
fprintf('%.2f\t\t%.4f\n',t1(ii), vt1(1, k)); % tabulating the data
k = k + 1;
  
end

% Calculating the velocity points with step size = 0.5s of time
fprintf('\n *** Step size = 0.5 s ***\n');
fprintf('\nTime (s)\tVelocity (m/s)\n\n');
j = 1;
for ii = 1:numel(t2)
if ii >= 0 && ii <= 10 % for 1st condition in limit
vt2(1, j) = 11 * t2(ii) * t2(ii) - 5 * t2(ii);
elseif ii > 10 && ii <= 20 % for 2nd condition in limit
vt2(1, j) = 1100 - 5 * t2(ii);
end
fprintf('%.2f\t\t%.4f\n',t2(ii), vt2(1, j)); % tabulating the data
j = j + 1;
end

% Tabulating values

% Plotting the graphs on same window with different figures
subplot(2, 1, 1)
plot(t1, vt1, '-k', 'LineWidth', 1.3)
xlabel('Time (s)')
ylabel('Velocity (m/s)')
title('Step Size = 1 s')

subplot(2, 1, 2)
plot(t2, vt2, '-b', 'LineWidth', 1.3)
xlabel('Time (s)')
ylabel('Velocity (m/s)')
title('Step Size = 0.5 s')

OUTPUT PLOT

Command Window Output


3.00 84.0000

3.50 117.2500
4.00 156.0000
4.50 200.2500
5.00 1075.0000
5.50 1072.5000
6.00 1070.0000
6.50 1067.5000
7.00 1065.0000
7.50 1062.5000
8.00 1060.0000
8.50 1057.5000
9.00 1055.0000
9.50 1052.5000
10.00 0.0000
10.50 0.0000
11.00 0.0000
11.50 0.0000
12.00 0.0000
12.50 0.0000
13.00 0.0000
13.50 0.0000
14.00 0.0000
14.50 0.0000
15.00 0.0000
15.50 0.0000
16.00 0.0000
16.50 0.0000
17.00 0.0000
17.50 0.0000
18.00 0.0000
18.50 0.0000
19.00 0.0000
19.50 0.0000
20.00 0.0000

Add a comment
Know the answer?
Add Answer to:
0sts10 1100-5t 10<ts20 Write a matlab code to calculate velocity v at: v(t) = 1. step...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT