Change sympref with shortcut line of code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Evan Jones
am 21 Okt. 2021
Kommentiert: Evan Jones
am 25 Okt. 2021
I want to change whether a symbolic equation outputs a decimal or fraction without having to type out/copy & paste the full line "sympref('FloatingPointOutput',false)"
It would be nice to have a line where I type "frac" or "dec" or some other shorthand to change this.
Here's a very quick example:
u = symunit
syms D_in D_out L k
sympref('FloatingPointOutput',false)
Rcond = log((D_out/2)/(D_in/2))*(1/(2*pi*L*k))
sympref('FloatingPointOutput',true)
D_in = 11.75*u.in
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 21 Okt. 2021
You could create a simple function to change the preference. You could even have that function retrieve the current value and set the preference to the other value (to toggle it.)
syms x
for k = 1:5
toggleFPO
queryFPO
y = expand((x*k).^(1/3))
end
function toggleFPO
sympref('FloatingPointOutput', ~sympref('FloatingPointOutput'));
end
function queryFPO
if sympref('FloatingPointOutput')
fprintf('FloatingPointOutput is enabled.\n')
else
fprintf('FloatingPointOutput is disabled.\n')
end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!