Graphing and converting sym p to long (or double) p.
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
Andrew Newell
on 29 Mar 2011
@Brutus, tags are supposed to be really short (one or two words).
Accepted Answer
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)));
1 Comment
Brutus Egor
on 29 Mar 2011
Categories
Find more on Conversion Between Symbolic and Numeric 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!