Is it possible to display a multiplication operator in symbolic math's displayFormula output?
조회 수: 13 (최근 30일)
이전 댓글 표시
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
채택된 답변
Sai Sumanth Korthiwada
2023년 3월 31일
편집: Sai Sumanth Korthiwada
2023년 3월 31일
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!
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!