when I try to plot the variable defined by syms, matlab reports errors
Afficher commentaires plus anciens
syms f(x1,x2);
f(x1,x2) = 2*(exp(-x1.^2)-exp(-x2.^2)).^2./(erf(x1)-erf(x2));
t=zeros(1,10);
for i = 1:200
x=randn(1,10);
y=randn(1,10);
t=t+f(10*x,10*y);
end
plot(1:10,double(t))
错误使用 mupadmex
Error in MuPAD command: Division by zero. [_power]
Evaluating: symobj::double
出错 sym/double (line 523)
Xstr = mupadmex('symobj::double', S.s, 0);
Réponses (1)
Walter Roberson
le 22 Mar 2022
Modifié(e) : Walter Roberson
le 22 Mar 2022
0 votes
You are using erf(). If you use erf(5.76) or more than the result is within round-off error of 1. But you are passing in 10*randn and randn is above 0.576 a lot of the time — roughly 1/3 of the time. So two randn both being above that would occur about 1/9 of the time. About 1/9th of those 200*10 = 2000 samples you generate will both have erf(10*x) that is 1.0 to within round-off. Now subtract those 1.0 values to get 0. And you divide by 0.
1 commentaire
yu yu
le 22 Mar 2022
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!