When using symunit and excecute the rewrite function on a long symfunc formula, an unexpected imaginary value occur in the result
Show older comments
When calculating formulas in physics, the symunit function set is very useful in avoiding physical unit calculation errors. But when Executing the rewrite function on a long symfunc formula, an unexpected imaginary value occur in the result.
I tried various methods to get rid of this imaginary value, but I had to do a very cumbersome task for example dividing and converting each formula repeatdly.
Please let me know how to solve this problem easily. And let me know if due to a syntax error or a bug in the program itself.
The following code shows my problem.
clear;
syms x;
u = symunit;
xVal = x * u.cm;
e_t = 8.85 * 1e-12 * u.F/u.m;
length = 1e-4 * u.cm;
carrierDensity = 10^15 * u.e * u.cm^-3;
Vsol = carrierDensity/2/e_t*length^2 - carrierDensity/2/e_t*xVal^2;
>> (3094850098213450687247810560000000/5477884673837807)*(([e]*[m])/([F]*[cm])) - ((309485009821345068724781056000000000000000*x^2)/5477884673837807)*(([e]*[m])/([F]*[cm]))
Vsol_V = rewrite(Vsol, u.V)
>> - x^2*(905184531.52542384719869293204256 + 0.00000000000000000000000000000029057403788672023408115096434705i)*[V] + 9.0518453152542384719869293204256*[V] -> why imaginary number emerge? how can i remove them?
Vsol_r = rewrite(carrierDensity/2/e_t*xVal^2, u.V);
Vsol_l = rewrite(carrierDensity/2/e_t*length^2, u.V);
Vsol_Vlr = Vsol_l - Vsol_r
>> 9.0518453152542384719869293204256*[V] - 905184531.52542384719869293204256*x^2*[V] -> no imaginary numbers. one of my solution, but it takes many time and ambiguous to apply code.
Answers (0)
Categories
Find more on Equations 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!