필터 지우기
필터 지우기

Stuck with one program

조회 수: 6 (최근 30일)
Gimmy Morales
Gimmy Morales 2013년 8월 29일
Hello, well I'm new using Matlab and is really awesome. I'm stuck with this exercise. Thanks for the help(:
13) A particle, initially at rest, is subjected to an applied force F.
For time t between 0 and a Time T F = Fm (1 - ((t – T)/T) )^2
For time t > T F = Fm
a) Write a script (Editor) file that requests the values of Fm, T, and t as input, and displays the value of F.
b) Plot F vs t use the values of Fm = 5, T = 10, t [0 – 20]
Create the variables xmax = 20 and ymax = F(1) and controls the graph axis using the command:
axis([0 xmax 0 ymax])
% this command goes after the plot command
Use SI units.
Call this program xxx_section_F3.m where xxx are your initials and substitute the section word by the section number that are 08 or 22.
Hint: create the t vector with linspace as example:
t = linspace(0, 20, 200)
for n = 1: 200;
F(n) = .. % when n=1 create F(1), when n = 2 create F(2), when n = 3 create F(3) and so on. You must use if command inside the for command
  댓글 수: 3
Gimmy Morales
Gimmy Morales 2013년 8월 29일
편집: Walter Roberson 2013년 8월 29일
Yes. I dont have an instructor for now, so I want to learn by myself.
This is what I got, I started to numbered the variables given
Fm=5; T=0;
t= linspace(0, 20, 200);
F = Fm (1 - ((t - T)/T) )^2
for t= 1:200
if t <=0
F = (1 - ((t - T)/T) )^2
else t > T
F = Fm
end
end
plot(t*200, F);
Walter Roberson
Walter Roberson 2013년 8월 29일
The first thing you are asked to do in the assignment is,
Write a script (Editor) file that requests the values of Fm, T, and t as input, and displays the value of F.
Your code does not request values for those variables. Refer to input()

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

채택된 답변

Walter Roberson
Walter Roberson 2013년 8월 29일

추가 답변 (1개)

David Sanchez
David Sanchez 2013년 8월 29일
I wrote the first part of your exercise, try to do the rest yourself:
Fm = input('value of Fm? ');
T = input('value of T? ');
t = input('value of t?');
if (t<T & t>0)
F = Fm *(1 - ((t - T)/T) ).^2;
elseif t>T
F = Fm;
end
fprintf('F = %g \n', F);
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 8월 29일
In that code if t == T then F will be left undefined. The same will be true if t < T but t <= 0.
I do note that the original question leaves those cases undefined.

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

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by