I using the following code to create a grid of the values for equation SF with numnerical values for x1 and x2 but have encountered the following error...
Error using symengine
Division by zero.
Error in sym/subs>mupadsubs (line 160)
G = mupadmex('symobj::fullsubs',F.s,X2,Y2);
Error in sym/subs (line 145)
G = mupadsubs(F,X,Y);
Error in Orthogonality_Check (line 51)
S2(i,j)=subs(S1(i),x2,iX1(j));
When I compute each value separately I do not have a problem, any advice would be appreciated thanks!
P.S values in grid are expected to be zero is this the cause of the problem?
% - Define variables
x1 = sym('x1');
x2 = sym('x2');
% - =======================================================================
% - Define dU and fu and create orthogonality function
f = [-1+9*x1-2*x1^3+9*x2-2*x2^3; 1-11*x1+2*x1^3+11*x2-2*x2^3];
dU = [2*x1^3-10*x1+x2+1;2*x2^3-10*x2+x1];
fu = f+dU;
Org = dU'*fu;
% - =======================================================================
% - Integrate orthogonal function
SF = int(Org);
% - =======================================================================
% - Set Limits for x1,x2...
LMB = 2;
n = 10;
iX1 = linspace(-LMB,LMB,n+1);
iX2 = linspace(-LMB,LMB,n+1);
for i=1:length(iX1)
S1(i)=subs(SF, x1,iX1(i));
for j=1:length(iX1)
S2(i,j)=subs(S1(i),x2,iX1(j));
end
end

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Aug. 2020

1 Stimme

You did not specify the variable of integration for Org. int() uses symvar to guess that x1 should be used. The integral has division by x2. When x2 is 0 that is problem.
Instead of using subs, you might want to use limit, as the limit as x2 approaches 0 is 0.

2 Kommentare

Guy Hotchin
Guy Hotchin am 26 Aug. 2020
Thanks, I'll try this out! I've edited so that the function is integrated twice, once by x1 and once by x2 so be mathematically correct, appreciate the error spot.
Removed the zero value from the array and replace with 1*10-n also works.
If your x1 and x2 are real-valued, I recommend
syms x1 x2 real
That simplifies some of the expressions, because your dU' invokes conjugate transpose, leading to a longer expression than necessary if the variables are real-valued.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by