Analytical differentiation in for loops
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
When I run the below with Master(i,1) replaced by Master(1,1) code runs with no errors.
Master = [1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1e6, 2e6, 5e6, 10e6; 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 1e5, 2e5, 5e5, 10e5];
syms x1
GRs = 200;
Rss = Master(1,1)+GRs*Master(1,1)*x1;
dRs = diff(Rss, x1);
dRs2 = diff(Rss^2, x1);
dRs_val = vpa(subs(dRs,x1,0));
dRs2_val = vpa(subs(dRs2,x1,0));
As soon as I put into for loop like below:
Master = [1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1e6, 2e6, 5e6, 10e6; 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 1e5, 2e5, 5e5, 10e5];
for i = 1:length(Master)
syms x1
GRs = 200;
Rss = Master(i,1)+GRs*Master(i,1)*x1;
dRs = diff(Rss, x1);
dRs2 = diff(Rss^2, x1);
dRs_val = vpa(subs(dRs,x1,0));
dRs2_val = vpa(subs(dRs2,x1,0));
end
I get the following error: NaN/Inf breakpoint hit for symvar.m on line 33.
33 n = inf;
Even after clearing workspace usinf the diff function on simple expressions copied from ttps://www.mathworks.com/help/symbolic/differentiation.html return same error. Restart fixes this issue.
Where am I going wrong?
5 commentaires
Walter Roberson
le 6 Nov 2024
I do not happen to have R2020a installed, but I checked R2019b and R2020b and symvar.m in them does not have any assignment of inf
Is it possible that you have Maple installed?
Réponse acceptée
Taylor
le 6 Nov 2024
You have an indexing issue. Master is a 2x13 array. By indexing to Master(i,1) you are exceeding the index bounds once you go past i=2. Change Master(i,1) to Master(1,i) and the code will run.
Master = [1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1e6, 2e6, 5e6, 10e6; 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 1e5, 2e5, 5e5, 10e5];
for i = 1:length(Master)
syms x1
GRs = 200;
Rss = Master(1,i)+GRs*Master(1,i)*x1;
dRs = diff(Rss, x1);
dRs2 = diff(Rss^2, x1);
dRs_val = vpa(subs(dRs,x1,0));
dRs2_val = vpa(subs(dRs2,x1,0))
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!