How can I substitute a variable?
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Shoaibur Rahman
il 20 Dic 2014
a= 5;
syms x
y = a*sin(x).^2 ./(sin(x) + cos(x));
subs ( y,{x},{2} )
2 Commenti
Shoaibur Rahman
il 20 Dic 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)
Categorie
Scopri di più su Code Performance in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!