i am trying to plot x(t) = 2[u(t)-u(t-1)]
here are my steps including function y = U(t)
function y = U(t)
t = -3:0.0001:3;
y= 1*(t>=0);
plot(t,U(t))
xlabel ('t')
ylabel('y')
axis([-3 3 -1 2])
grid on
title('plot of the unit step function U(t)')
end
x(t) = 2[U(t)-U(t-1)]
x = @(t) 2*(U(t)-U(t-1))
plot(t,x(t))

댓글 수: 1

What is the error you are getting? Make sure you define subfunctions at the end of the script.

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

답변 (1개)

Adam Danz
Adam Danz 2020년 3월 28일
편집: Adam Danz 2020년 3월 31일

0 개 추천

function y = U(t)
t = -3:0.0001:3;
y= 1*(t>=0);
plot(t,U(t))
% ^^^^problem
You're recursively calling the U(t) function from within the function.
When sharing an error message, please share the entire copy-pasted message.

댓글 수: 3

Walter Roberson
Walter Roberson 2020년 3월 31일
x(t) = 2[U(t)-U(t-1)]
Is invalid syntax in MATLAB. MATLAB does not have any implied multiplication at all, not even in the symbolic toolbox.
Adam Danz
Adam Danz 2020년 3월 31일
That line is also invalid because t are floating point numbers rather than index values.
Walter Roberson
Walter Roberson 2020년 4월 1일
But U is a function, so it doesn't matter that t is not index values.

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

카테고리

질문:

2020년 3월 28일

댓글:

2020년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by