How can I substitute a variable?
Afficher commentaires plus anciens
Dear community,
How can I use 'subs' here?
I defined x array to interpolate y and here I want to substitute x= 2 into y . By the way, how can I substitute x into y?
a= 5;
x = 0:pi/10:pi;
y = a*sin(x).^2 ./(sin(x) + cos(x));
subs ( y,{x},{2} ) --> it won't work by doing like this
Thanks in advance
Réponse acceptée
Plus de réponses (1)
Shoaibur Rahman
le 20 Déc 2014
a= 5;
syms x
y = a*sin(x).^2 ./(sin(x) + cos(x));
subs ( y,{x},{2} )
2 commentaires
Shoaibur Rahman
le 20 Déc 2014
subs is a symbolic substitution in Matlab. So, what if you use any one of the following techniques:
a= 5;
x = 0:pi/10:pi;
y = a*sin(x).^2 ./(sin(x) + cos(x));
interp1(x,y,2)
This approximates a value of y at x = 2, but may not exact. Second, you can define y as function of x, then replace x by any value. In this case you can expect an exact value.
a = 5;
y = @(x) a*sin(x).^2 ./(sin(x) + cos(x));
y1 = y(0:pi/10:pi);
y2 = y(2)
Catégories
En savoir plus sur Code Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!