Is it possible to display a multiplication operator in symbolic math's displayFormula output?
16 views (last 30 days)
Show older comments
I am using the Symbolic Math Toolbox's function displayFormula() in Live Editor to display a series of equations and subsequent answers. When I try and show intermediate steps, filling the equations with the actual values found, where there would be a multiplication symbol (∗), it just outputs blank space. This works for variables where a*b displays , but with numbers 1*1 it displays as , which looks like eleven.
The code I'm working with:
syms x1 x2 x3 N1 N2 N3 s t N_i
dNs = "diff(N_i(s,t),s)"; % dN as a string for display
N1(s,t) = 1-s-t; % Shape functions
N2(s,t) = s;
N3(s,t) = t;
dN1s = diff(N1,s); % Calc partial derivatives
dN2s = diff(N2,s);
dN3s = diff(N3,s);
x1 = 0; % set x coords
x2 = 1;
x3 = 0;
sumdNsx = dN1s*x1+dN2s*x2+dN3s*x3;
displayFormula("symsum(dNs*x_i,i,1,3)==dN1s*x1+dN2s*x2+dN3s*x3==sumdNsx")
Output:
Should be something like:
or
* Side note: Wouldn't mind getting rid of the parentheses too.
0 Comments
Accepted Answer
Sai Sumanth Korthiwada
on 31 Mar 2023
Edited: Sai Sumanth Korthiwada
on 31 Mar 2023
Hi Tim,
As of Symbolic Math Toolbox R2022b, multiplication symbol (*) outputs a blank space for integers as well. Because the input given to the function gets evaluated. As a workaround, you can use
"'*'" % use this to add a '*' in between the formula
Also, pass a cell array of character vectors [ ] rather than passing a string, if you want to use '*' symbols in the formula.
syms x1 x2 x3 N1 N2 N3 s t N_i
dNs = "diff(N_i(s,t),s)"; % dN as a string for display
N1(s,t) = 1-s-t; % Shape functions
N2(s,t) = s;
N3(s,t) = t;
dN1s = diff(N1,s); % Calc partial derivatives
dN2s = diff(N2,s);
dN3s = diff(N3,s);
x1 = 0; % set x coords
x2 = 1;
x3 = 0;
sumdNsx = dN1s*x1+dN2s*x2+dN3s*x3;
% displayFormula("symsum(dNs*x_i,i,1,3)==dN1s*x1+dN2s*x2+dN3s*x3==sumdNsx")
%% instead try:
% to use '*' in the formula, workaround:
displayFormula(["symsum(dNs*x_i,i,1,3)==dN1s","'* '","x1+dN2s","'* '","x2+dN3s","'* '","x3==sumdNsx"])
% to use '(' in the formula, workaround:
displayFormula(["symsum(dNs*x_i,i,1,3)==dN1s","'('","x1","')+'","dN2s","'('","x2","')+'","dN3s","'('","x3","')='","sumdNsx"])
Hope this helps!
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!