How to plot this function with 2 variables?

Hello, I’m having a hard time plotting z2(t). I keep getting the error “input must be a function or functions of a single variable”. I’m not sure how to properly define “u”.

댓글 수: 2

Marisa
Marisa 2023년 10월 30일
Dyuman Joshi
Dyuman Joshi 2023년 10월 30일
이동: Dyuman Joshi 2023년 10월 30일
As you are using fplot, the expected input is a function handle.
And the syntax to define a function handle is
name_of_handle = @(independent_variables) relation_or_expression_of_independent_variables
%For the first example, it translates to
z1 = @(t) exp(t);
Refer to these links for more information -

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

답변 (1개)

Voss
Voss 2023년 10월 30일
t = -2:0.01:2;
z1 = exp(t);
z2 = 2*(t+1 >= 0);
z3 = 0.5*sin(7*t);
hold on
grid on
plot(t,z1,'-','LineWidth',2)
plot(t,z2,':','LineWidth',2)
plot(t,z3,'--','LineWidth',2)
xlabel('t')
ylabel('z')
legend("z"+[1 2 3])
ylim([-1 8])

댓글 수: 9

Just a note -
z2 = 2*(t+1 >= 0);
">= 0" is not mentioned in the question
Voss
Voss 2023년 10월 30일
I interpret u(t) to be the unit step function.
Dyuman Joshi
Dyuman Joshi 2023년 10월 30일
Alright.
Marisa
Marisa 2023년 10월 30일
Thank you, The original question wants me to plot z2(t)=2u(t+1), I’m not sure how to plot this since it also involves “u”
The signal u(·) in the question most likely refers to the unit step function, which can be represented by the Heaviside function.
t = -2:0.001:2;
z2 = 2*heaviside(t + 1);
plot(t,z2,':','LineWidth',2), grid on
xlabel('t')
ylabel('z')
ylim([-1 8])
Marisa
Marisa 2023년 10월 30일
Okay the example mentioned Heaviside but I tried to use that and wasn’t getting it right. This makes sense! This worked, thank you so much! I was just putting Heaviside in incorrectly.
Voss
Voss 2023년 10월 30일
@Marisa: Or if you don't have the Symbolic Math Toolbox, you can write down what the unit step function is in your definition of z2, as I have done in my answer.
Sam Chak
Sam Chak 2023년 10월 30일
Good to hear that, @Marisa. 👍
Sam Chak
Sam Chak 2023년 10월 30일
In the mathematical representation of linear physical systems (later in your course), you may encounter the state-space equation, . But this is not the unit step function. Please keep that in mind.

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

카테고리

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

제품

릴리스

R2023b

질문:

2023년 10월 30일

이동:

2023년 10월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by