1

I want to convert a polynomial expression into an array of characters in MATLAB. We are using the command char. On my computer, char will change the format of the coefficients of a polynomial to scientific notation.

For example,

char(x^2 + 0.0001*x)

will output $x^2 +1e-4\cdot x$ as an array of chars. That will generate an error in my program.

Can we get an array which contains $x^2+0.0001\cdot x$ of length $12$ instead of an array containing $x^2+1e-4\cdot x$ which is of length $10$ by using char? If there is a way of turning off the scientific notation in MATLAB, that will be great!

Thanks!

daOnlyBG
  • 2,711
Pew
  • 643
  • char(x^2 + 0.0001*x) does not return x^2 +1e-4*x, it returns the char that corresponds to the value of $x^2+0.0001x$. Do you simply want the string x^2+0.0001*x? Then just write 'x^2+0.0001*x'. – Eff Oct 31 '14 at 20:39
  • It returns an array of chars. x^2 + 0.0001*x is a symbolic expression which has no value. x is a variable defined by syms x. This is an example, I would like to do that for any input polynomial f by char(f). – Pew Oct 31 '14 at 20:51
  • Do you use syms x or what? And then char(x^2 + 0.0001*x) returns the $1$ by $10$ array of chars x^2+1e-4*x? – Eff Oct 31 '14 at 20:55
  • Yes, I use syms x, and it returns 1 by 10 array of chars x^2+1e-4*x – Pew Oct 31 '14 at 21:40

1 Answers1

0

Try converting your symbolic expression to variable precision arithmetic using vpa before using char:

syms x;
y = x^2 + 0.0001*x;
char(vpa(y))

See the documentation for vpa and for digits for how to adjust the conversion.

horchler
  • 3,203