Substitute an array of number for a symbolic variable

55 vues (au cours des 30 derniers jours)
David Arnold
David Arnold le 1 Nov 2012
Commenté : Walter Roberson le 12 Juil 2019
Hi,
I have:
syms x y
f=x^3+y^3+3x^2+2y^2+9
fx=diff(f,x)
now, I'd like to substitute these two vectors of x and y values into the expression fx.
x=[1,2,3,4,5]
y=[6,7,8,9,10]
How do I do that with the subs command? If I can't do that with the subs command, what do you recommend?
David.
  1 commentaire
Star Strider
Star Strider le 1 Nov 2012
Modifié(e) : Star Strider le 1 Nov 2012
Question: Do you want a matrix with the function evaluation of fx for each value of (x,y) as an individual element?
What version of MATLAB do you have? Beginning with 2012a, symbolic functions are possible.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 1 Nov 2012
subs(fx, {x, y}, {[1,2,4,5,6}, [6,7,8,9,10]})
This syntax is documented relatively far down in the examples.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 1 Nov 2012
syms x y
f=x^3+y^3+3*x^2+2*y^2+9
fx=diff(f,x)
x=[1,2,3,4,5]
y=[6,7,8,9,10]
eval(f)
eval(fx)

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by