Square root symbol does not display using displayFormula function

15 Ansichten (letzte 30 Tage)
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 Kommentar
Paul
Paul am 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)
capacitance = 
0.0000019999999999999999094962236517725
displayFormula("capacitance")
0.0000019999999999999999094962236517725
S = "Q_o = sqrt(2*resistor_dissipated_energy*capacitance)"
S = "Q_o = sqrt(2*resistor_dissipated_energy*capacitance)"
displayFormula(S)
How does your result display 2.0e-6?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Jan. 2024
S = ["Q_o=sqrt","'('","'2'","'*'","resistor_dissipated_energy","'*'","capacitance","')'"];
symstr = ["'Capacitor initial charge:'"," ",S];
symstr
symstr = 1×10 string array
"'Capacitor initial…" " " "Q_o=sqrt" "'('" "'2'" "'*'" "resistor_dissipate…" "'*'" "capacitance" "')'"
displayFormula(symstr)
You broke up the sqrt() across several string parts. Each string part is processed seperately.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by