Filter löschen
Filter löschen

Format the left hand side of a symbolic expression in a Live Script

6 Ansichten (letzte 30 Tage)
Carlos Souto
Carlos Souto am 11 Mär. 2022
Bearbeitet: Paul am 13 Mär. 2022
In a live script, the following code:
syms A_1 x alpha
N_phi = A_1*x*cos(alpha)
outputs the following:
N_phi =
Is there a simple way to format the left side of the equation so that the output is as follows?

Antworten (1)

Walter Roberson
Walter Roberson am 11 Mär. 2022
No, there is no simple way to do that.
The closest you can get to that is to create an equation instead,
syms A_1 x alpha N_phi
N_phi == A_1*x*cos(alpha)
ans = 
  3 Kommentare
Walter Roberson
Walter Roberson am 12 Mär. 2022
syms A_1 x alpha N_phi
N_phi = A_1*x*cos(alpha);
disp(sym('N_phi') == N_phi)
Paul
Paul am 13 Mär. 2022
Bearbeitet: Paul am 13 Mär. 2022
Very, very high ratio of utility to complexity. I've been looking for this
I'll note that for a symfun object it looks like str2sym has to be used.
syms S_p(omega)
S_p(omega) = 5*omega;
disp(str2sym('S_p(omega)') == S_p(omega))
Prototype function to work with a sym or symfun input
syms S_p(omega,alpha)
S_p(omega,alpha) = omega + alpha
S_p(omega, alpha) = 
symdisp(S_p) % symfun input
S_p = omega^2 + alpha^2
S_p = 
symdisp(S_p) % sym input
function symdisp(in)
rhs = in;
lhs = string(inputname(1));
args = argnames(in);
if ~isempty(args)
argstr = "(" + join(string(args),",") + ")";
else
argstr = "";
end
disp(str2sym(lhs + argstr) == rhs)
end

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by