Square root symbol does not display using displayFormula function
14 views (last 30 days)
Show older comments
David Cole
on 2 Jan 2024
Answered: Walter Roberson
on 5 Jan 2024
I had added an * symbol to my string to make the equation more readable after the numbers have been inserted (see picture below). I want the square root symbol to be displayed not sqrt. See the picture below. Maybe there is a better way to add the * symbol so the square root symbol will be displayed.
%Given:
u=symunit;
%Variable-precision arithmetic
capacitance = vpa(2e-6);
displayFormula(["'Given capacitance: '","C = capacitance*u.F"])
displayFormula(["'Given intial charge: '"," ","Q = Q_o"])
resistance = 10.0;
displayFormula(["'Given resistance: '","R = resistance*u.Ohm"])
resistor_dissipated_energy = vpa(0.0036);
displayFormula(["'Given resistor dissipated energy: '","w_R = resistor_dissipated_energy*u.J"])
%Solution:
disp("charge [Q] = capacitance [C] * voltage [V]")
disp("energy [w] = charge [Q] * voltage [V]")
displayFormula(["'Capacitor energy: '","w_C=(1/2)*C*V^2*u.J"])
disp("Rearrange charge equation and solve for V")
displayFormula(["'Voltage: '","V = Q/C"])
disp("Substitute rearranged equation into capacitor energy equation")
displayFormula(["'Capacitor Energy (subsitution): '","w_C=(1/2)*C*(Q/C)^2"])
S = "w_C=(1/2)*(Q^2/C)";
symstr = ["'Capacitor Energy:'","w_C=(1/2)*(Q^2/C)"];
displayFormula(["'Capacitor Energy (simplified): '","w_C=(1/2)*(Q^2/C)"])
disp("Rearrange capacitor energy equation and solver for charge [Q]")
displayFormula(["'Capacitor intial charge: '","Q_o=sqrt(2*w_c*C)"])
%build the string like this to display the * symbol
%not working here
S = ["Q_o=sqrt","'('","'2'","'*'","resistor_dissipated_energy","'*'","capacitance","')'"];
symstr = ["'Capacitor initial charge:'"," ",S];
displayFormula(symstr)
%end of not working
capacitor_intial_charge=sqrt(2*resistor_dissipated_energy*capacitance)*10^6*u.uJ;
displayFormula(["'Capacitor intial charge: '","Q_o = capacitor_intial_charge"])
1 Comment
Paul
on 5 Jan 2024
Hi David,
I don't have a solution. But I am curious how your result shows that 2.0e-6.
resistor_dissipated_energy = vpa(0.0036);
capacitance = vpa(2e-6)
displayFormula("capacitance")
S = "Q_o = sqrt(2*resistor_dissipated_energy*capacitance)"
displayFormula(S)
How does your result display 2.0e-6?
Accepted Answer
Walter Roberson
on 5 Jan 2024
S = ["Q_o=sqrt","'('","'2'","'*'","resistor_dissipated_energy","'*'","capacitance","')'"];
symstr = ["'Capacitor initial charge:'"," ",S];
symstr
displayFormula(symstr)
You broke up the sqrt() across several string parts. Each string part is processed seperately.
0 Comments
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox 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!