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!

답변 (3개)

Image Analyst
Image Analyst 2016년 12월 28일

0 개 추천

Hint:
tn = 0 : 0.001 : 15;

댓글 수: 1

Alper Camci
Alper Camci 2016년 12월 28일
I finished Matlab for Enginners book from Holly Moore so I know this much... I need to see solition of the problem.

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

Image Analyst
Image Analyst 2016년 12월 28일

0 개 추천

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

Alper Camci
Alper Camci 2016년 12월 28일
편집: Alper Camci 2016년 12월 29일
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 2016년 12월 28일
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.

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

Majed Mabadi
Majed Mabadi 2020년 10월 11일

0 개 추천

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

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:

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

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

제품

태그

질문:

2016년 12월 28일

댓글:

2020년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by