matlab - “输入参数过多”尝试在 MATLAB 中运行脚本时出错
问题描述
我正在尝试运行讲师给我的脚本,但由于某个功能而出现错误。该函数位于一个单独的文件中,但位于同一目录中。该函数是一个方程,将在主脚本中双重集成。
这是主脚本(此文件名为“ele_assignment_ii.m”:
clear
format short
%The following part is for part (a)
dx = input('Enter the integration increment dx... \n >');
dy = input('Enter the integration increment dy... \n >');
total_charge=0;
for x=0:dx:1,
for y=0:dy:1,
total_charge=rho_s_fun(x,y)*dx*dy+total_charge;
end
end
disp(sprintf('The total charge computed by manual double'));
disp(sprintf(' integration is %d nC',total_charge));
total_charge=dblquad(@rho_s_fun, 0, 1, 0, 1);
disp(sprintf('The total charge computed by the functional'))
disp(sprintf(' double integration is %d n',total_charge))
%The following for part (b)
Etotal=0;
for x=0:dx:1,
for y=0:dx:1,
rminusrprime=[-x -y 5];
numerator=rho_s_fun(x,y)*1e-9*dx*dy*rminusrprime;
denominator=4*pi*1e-9/(36*pi)*norm(rminusrprime)^3;
Etotal=Etotral+numerator/denominator;
end
end
disp(sprintf('The electric field computed by manual double'));
disp(sprintf(' integration is (%d, %d, %d) V/m',...
Etotal(1), Etotal(2), Etotal(1)))
下面是函数代码(这个文件名为 rho_s_fun.m):
function rho_s_fun = rho_s_fun()
rho_s_fun = @(x,y) (x.*y).*(x.^2 + y.^2 + 25).^(3/2);
end
最后,这是我运行主脚本时的错误:
>> ele_assignment_ii
Enter the integration increment dx...
>2
Enter the integration increment dy...
>2
Error using rho_s_fun
Too many input arguments.
Error in ele_assignment_ii (line 10)
total_charge=rho_s_fun(x,y)*dx*dy+total_charge;
据我了解,这个错误显然导致了第 10 行的后续错误。
如何更改此代码以使其正常工作?
解决方案
推荐阅读
- c# - IoT 中心 C2D 消息属性溢出到正文
- xml - INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: 解析失败./base.apk: AndroidManifest.xml]
- javascript - 无法在 firebase 功能上将视频与 ffmpeg 结合
- python -
和
网页抓取时的顺序 - r - ddply() 说我的数据中没有一些缺失值,知道为什么吗?
- python - 将 Android 应用程序连接到 Python 服务器
- sql - 如何在 SQL 中使用其他表中的数据创建小计
- google-apps-script - 由于大数据集,谷歌脚本不断崩溃
- android - 使用 Gson 反序列化动态 API 响应
- apache-spark - HDInsigh Spark 如何使用以下代码