when I try to plot the variable defined by syms, matlab reports errors
显示 更早的评论
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);
回答(1 个)
Walter Roberson
2022-3-22
编辑:Walter Roberson
2022-3-22
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!