Graphing and converting sym p to long (or double) p.
1 view (last 30 days)
Show older comments
>>x=linspace(-1,1,100) >>p = 1/26 + 25/26*x- (25/26*x-25/26)*x + ((625/1313*x-1250/1313)*x-625/1313)*x >> plot(x,double(p))
??? Error using ==> eval Undefined function or variable 'x'. Error in ==> sym.double at 45 D = reshape(eval(X),siz);
Questions: (1) How do I convert sym x (lower case variable x) to long (because I wanted it to be to the 16th decimal places)? (2) How do I get this Polynomial expression called 'p' to graph along a linspace between -1 and 1 of 100 intervals between them?
1 Comment
Accepted Answer
Brutus Egor
on 29 Mar 2011
2 Comments
Christopher Creutzig
on 6 Apr 2011
You really should click the “accept answer” next to Walter's answer, not next to your own comment.
Walter Roberson
on 6 Apr 2011
I figure it balances out the times when I get a simple reference to the FAQ Accepted ;-)
More Answers (1)
Walter Roberson
on 29 Mar 2011
The code you show is not your actual code. Your actual code would give an error,
??? Error using ==> mtimes
Inner matrix dimensions must agree.
In order to fix that you would have to use .* instead of * in your definition of p.
The code you show does not use symbolic variables at all.
The function you give cannot be expressed accurately to 16 decimal places using double precision floating point numbers -- only to 15 1/2 decimal places. Generally speaking, if you need more than 15 decimal places you need to use symbolic numbers.
If what you have is
x = linspace(-1,1,100);
sym X
p = 1/26 + 25/26.*X- (25/26.*X-25/26).*X + ((625/1313.*X-1250/1313).*X-625/1313).*X;
then you can use:
plot(x, double(subs(p,x,X)));
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!