How do I write x(t/2) using handle operator @

조회 수: 4 (최근 30일)
hazel grace
hazel grace 2021년 5월 30일
답변: Star Strider 2021년 5월 30일
I have tried to create a function x(t/2) using handle like this:
x = @(t/2);
however, this gives an error. I can also not write it in terms of another variable like this
y = t/2; x = @(y);
since this also gives an error and says that t was not declared. I can not use syms to declare t since it is not allowed in the question. Can someone please help me with this?
  댓글 수: 2
Torsten
Torsten 2021년 5월 30일
편집: Torsten 2021년 5월 30일
You must write it as a function of t. Only when you valuate the function handle, you can insert t/2.
x = @(t) t.^2;
t = linspace(0,1,100);
y = x(t/2);
plot(t,y)
Jan
Jan 2021년 5월 30일
"a function x(t/2)" is not clear. What do you want as output of the function?

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

채택된 답변

Star Strider
Star Strider 2021년 5월 30일
Try something like this —
x = @(t) (t/2);
t = 42;
y = x(t/2)
y = 10.5000
See the documentation section on Anonymous Funcitons for details.
.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by