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!

Réponses (3)

Image Analyst
Image Analyst le 28 Déc 2016

0 votes

Hint:
tn = 0 : 0.001 : 15;

1 commentaire

Alper Camci
Alper Camci le 28 Déc 2016
I finished Matlab for Enginners book from Holly Moore so I know this much... I need to see solition of the problem.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 28 Déc 2016

0 votes

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 commentaires

Alper Camci
Alper Camci le 28 Déc 2016
Modifié(e) : Alper Camci le 29 Déc 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!
Image Analyst
Image Analyst le 28 Déc 2016
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.

Connectez-vous pour commenter.

Majed Mabadi
Majed Mabadi le 11 Oct 2020

0 votes

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 commentaires

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:

Connectez-vous pour commenter.

Catégories

En savoir plus sur General Applications dans Centre d'aide et File Exchange

Produits

Tags

Commenté :

le 11 Oct 2020

Community Treasure Hunt

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

Start Hunting!

Translated by