Graphing and converting sym p to long (or double) p.

>>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

@Brutus, tags are supposed to be really short (one or two words).

Sign in to comment.

 Accepted Answer

Thank you so much. You answered 2 questions in 1 command. You R-O-C-K!!!

2 Comments

You really should click the “accept answer” next to Walter's answer, not next to your own comment.
I figure it balances out the times when I get a simple reference to the FAQ Accepted ;-)

Sign in to comment.

More Answers (1)

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

Thank you so much. You answered 2 questions in 1 command. You R-O-C-K!!!

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!