Symbolic substitution: Subs command is substituting zeros with 'new' despite 'old' not being defined as zero - why?
Mostrar comentarios más antiguos
I've got a simple piece of symbolic code below. It all seems to work well, except one strange thing happens. Vx1_before contains mostly zeros. For some reason, in the loop in the code, the subs command substitutes these zeros for the variable heavi_x1_9... the subs 'old' input is not zero, so really, it shouldn't act at all on these entries.
Precis: Upon running the code, most of Vx1_after contains the symbolic variable heavi_x1_9, although these entries should never have been substituted and should be zeros.
I hope someone can explain to me what is happening, why these elements of Vx1_before have been substituted despite not even containing the value to be substituted.
clear;
clc;
tx1=[0.06 0.06 0.06 0.06 0.06 0.144 0.144 0.144 0.144 0.144]
syms heavi_y5 heavi_x1_5 x y
Vx1_before=[heavi_y5*heavi_x1_5*((250*x)/21 - 12/7)^4*((125*y)/3 - 1)^4;-(500*heavi_y5*heavi_x1_5*y*((250*x)/21 - 12/7)^4*((125*y)/3 - 1)^3)/3;-4*heavi_y5*heavi_x1_5*((250*x)/21 - 5/7)*((250*x)/21 - 12/7)^3*((125*y)/3 - 1)^4;(2000*heavi_y5*heavi_x1_5*y*((250*x)/21 - 5/7)*((250*x)/21 - 12/7)^3*((125*y)/3 - 1)^3)/3;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0]
heaviside_vector_x1=[0;0;0;0;heaviside(x - 3/50) - heaviside(x - 18/125);0;0;0;0]
m1=length(tx1)-1;
for k=1:m1
Vx1_after=subs(Vx1_before,sprintf('heavi_x%d_%d', 1, k),heaviside_vector_x1(k));
end
Vx1_after
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Code Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!