Help about a MATLAB Question

Hi everyone. I just started to learn MATLAB. So I'm trying to develop myself with solving problems. And here is a question in the PDF that I could not solve because there are a lot of variables in the equation and I can't connect them each other and write the while loops. I would be grateful to you if you solved this question. Thanks a lot!

Answers (3)

Hint:
tn = 0 : 0.001 : 15;

1 Comment

I finished Matlab for Enginners book from Holly Moore so I know this much... I need to see solition of the problem.

Sign in to comment.

OK Alper, assuming this is just your self-learning and I'm not doing your hojmework for you, try this code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
T = 0.001;
C = 0.008;
t = 0 : T : 16;
A = 30 * ones(1, length(t));
v = zeros(1, length(t));
n = 1;
while n <= length(t)
v(n+1) = v(n) + T * (A(n) - C * v(n) ^ 2);
% Break when we hit 60
if v(n+1) >= 60
% Save the index and time.
t60 = t(n+1)
n60 = n;
break; % Quit the loop.
end
n = n + 1;
end
plot(t(1:n60), v(1:n60), 'b-', 'LineWidth', 2);
grid on;
title('Velocity', 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('Velocity', 'FontSize', fontSize);
hold on;
% Plot red circle.
plot(t(n60), v(n60), 'ro', 'MarkerSize', 15, 'LineWidth', 2);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Now decelerate.
% Make acceleration -1 from that point on
A(n60+1:end) = -2;
n = n60;
nStop = length(t);
tStop = t(nStop);
while n <= length(t)
v(n+1) = v(n) + T * (A(n) - C * v(n) ^ 2);
% Break when we hit 0
if v(n+1) <= 0
% Save the index and time.
tStop = t(n+1)
nStop = n;
break; % Quit the loop.
end
n = n + 1;
end
plot(t(1:nStop), v(1:nStop), 'b-', 'LineWidth', 2);
grid on;
ylim([0, 80]);
title('Velocity', 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('Velocity', 'FontSize', fontSize);
% Plot red square.
plot(t(nStop), v(nStop), 'rs', 'MarkerSize', 15, 'LineWidth', 2);
% Put up legend.
textFontSize = 23;
text(10, 75, '--- v(t)', 'Color', 'r', 'FontSize', textFontSize);
caption = sprintf('o = t_6_0 = %.2f sec', t60);
text(10, 70, caption, 'Color', 'r', 'FontSize', textFontSize);
% Plot square
text(10, 65.7, char(hex2dec('25a1')), 'Color', 'r', 'FontSize', textFontSize);
caption = sprintf(' = t_S_t_o_p = %.2f sec', t(nStop));
text(10.2, 65, caption, 'Color', 'r', 'FontSize', textFontSize);

2 Comments

Alper Camci
Alper Camci on 28 Dec 2016
Edited: Alper Camci on 29 Dec 2016
I'm grateful to you! By the way, I am really trying to improve myself by solving this questions and this is one of them. And I need to solve this questions for start to SIMULINK. Thank you very much Image Analyst!
I can't help you with any Simulink followup questions, but if my answer to this one solved your question, then can you "Accept this answer"? Thanks in advance.

Sign in to comment.

Majed Mabadi
Majed Mabadi on 11 Oct 2020
Create a variable a that is a row vector with the following elements:9,1,3^2,7/4,0,2.25*8.5,0.8,and sin(pi/8)

2 Comments

You should have posted this in your own, separate question, not as an answer to Alper's question. If you had, someone probably would have given you the answer
a = [9, 1, 3^2, 7/4, 0, 2.25*8.5, 0.8, sin(pi/8)]
or possibly this:

Sign in to comment.

Categories

Find more on General Applications in Help Center and File Exchange

Products

Tags

Asked:

on 28 Dec 2016

Commented:

on 11 Oct 2020

Community Treasure Hunt

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

Start Hunting!