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

4 vues (au cours des 30 derniers jours)
hazel grace
hazel grace le 30 Mai 2021
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 commentaires
Torsten
Torsten le 30 Mai 2021
Modifié(e) : Torsten le 30 Mai 2021
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 le 30 Mai 2021
"a function x(t/2)" is not clear. What do you want as output of the function?

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 30 Mai 2021
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.
.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by