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
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)
displayFormula("capacitance")
S = "Q_o = sqrt(2*resistor_dissipated_energy*capacitance)"
displayFormula(S)
How does your result display 2.0e-6?
채택된 답변
Walter Roberson
2024년 1월 5일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!