Square root symbol does not display using displayFormula function
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
David Cole
el 2 de En. de 2024
Respondida: Walter Roberson
el 5 de En. de 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 comentario
Paul
el 5 de En. de 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?
Respuesta aceptada
Walter Roberson
el 5 de En. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!