My professor is driving me crazy.

조회 수: 1 (최근 30일)
Athanasios Naminsenoiazi
Athanasios Naminsenoiazi 2018년 10월 20일
댓글: Image Analyst 2018년 10월 20일
So i have the following exercise i have to use this formula with a t that starts at 0 and goes all the way to 50 with a step of 5. calculate and present in a table. i did this,
step=5
tmax=50
X = [0:step:tmax;10*(1-exp(-0.2*(0:step:tmax)))];
and he said to me that the formula is not correct. I have been staring at it for an hour and it's driving me nuts. Can someone please explain to me were i went wrong and why? :/
formula

답변 (2개)

Image Analyst
Image Analyst 2018년 10월 20일
편집: Image Analyst 2018년 10월 20일

I'd bet it's because you, for some reason, decided to change the name of the variable from u, which your professor wanted, to X. And you didn't even use t AT ALL !

Why did you do that? Give him what he wants.

  댓글 수: 4
Athanasios Naminsenoiazi
Athanasios Naminsenoiazi 2018년 10월 20일
편집: Athanasios Naminsenoiazi 2018년 10월 20일
Here is the full code, X is just temporary
tmax = 50;
step = 5;
X = [0:step:tmax;10*(1-exp(-0.2*(0:step:tmax)))];
t = [];
ut = [];
for i=1:2
for j=1:11
if i == 1
t = [t;X(i,j)];
elseif i == 2
ut = [ut;X(i,j)];
end
end
end
T = table(t,ut);
T
Plus i never used t at all because this way is way more elegant that having a loop...
Image Analyst
Image Analyst 2018년 10월 20일
Did he ask for a table? If not, why did you make one?
This is what I'd do
t = 0 : 5 : 50;
u = 10 * (1 - exp(-0.2 * t));
Simply create vector t then use it to create the vector u that he wants.
From your original post, I don't see any need to use for loops, tables, variables called X or T, or even 2-D matrices. The two lines of code above should do it.

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


James Tursa
James Tursa 2018년 10월 20일

Maybe he wants the results presented in columns?

tmax = 50;
step = 5;
t = (0:step:tmax)'; % make it a column
X = [t,10*(1 - exp(-0.2*t))]; % put the result in columns
  댓글 수: 2
Athanasios Naminsenoiazi
Athanasios Naminsenoiazi 2018년 10월 20일
Did that later on the code. Didn't post it all because 1.) It works and 2.) he specifically said that the formula is wrong...
James Tursa
James Tursa 2018년 10월 20일
편집: James Tursa 2018년 10월 20일
Wrong in what way? The code does match the formula you posted. Is there another formula you should be using?

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by