Why can't a variable holding an equation be used to make a function handle?

1 vue (au cours des 30 derniers jours)
%% Test
syms x
eqn(x) = x^2
func = @(x) eqn
func(2)

Réponse acceptée

madhan ravi
madhan ravi le 20 Fév 2020
I would simply use matlabFunction() as sir Walter says but maybe you have the follwing in mind:
func = @(x) eqn(x)
  2 commentaires
Spencer Kranz
Spencer Kranz le 20 Fév 2020
I just forgot the (x) on the end of eqn. I feel like such an idiot. So much time wasted. ughhh
Spencer Kranz
Spencer Kranz le 20 Fév 2020
thank you though!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 20 Fév 2020
Use matlabFunction()
  2 commentaires
Walter Roberson
Walter Roberson le 20 Fév 2020
Suppose you were to do
A=1; B=2;
C=A+B;
D = @(A) C
What value would you expect D(0) to have? What value would you expect D(5) to have?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by