Square root symbol does not display using displayFormula function

조회 수: 12 (최근 30일)
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
Paul
Paul 2024년 1월 5일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2024년 1월 5일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by