How can I substitute a variable?
Show older comments
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
Accepted Answer
More Answers (1)
Shoaibur Rahman
on 20 Dec 2014
a= 5;
syms x
y = a*sin(x).^2 ./(sin(x) + cos(x));
subs ( y,{x},{2} )
2 Comments
Shoaibur Rahman
on 20 Dec 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)
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!