Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-11-26, 03:02   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 The variable is not being assigned a value for some reason. (MATLAB)

For some reason, result_spmd is not being assigned a value and I am not sure what I have done wrong. Can someone please help me?



spmd(4)
interval_size = (finish-start) / No_intervals;
range = finish - start;
start_spmd = ((labindex - 1) * (range/4)) + start;
finish_spmd = start_spmd + (range/4);
fprintf ("Worker %d will count from %f to %f ", labindex, start_spmd, finish_spmd );


for x = start_spmd:interval_size:(finish_spmd - interval_size)
result_spmd = result_spmd + 0.5 * ( Function_to_Integrate(x) + Function_to_Integrate(x+interval_size) ) * interval_size; %Issue is on this line
end

end

fprintf ("The value from worker 1 is %f\n", result_spmd{1} );
fprintf ("The value from worker 2 is %f\n", result_spmd{2} );
fprintf ("The value from worker 3 is %f\n", result_spmd{3} );
fprintf ("The value from worker 4 is %f\n", result_spmd{4} );
result_total = ( result_spmd{1} + result_spmd{2} + result_spmd{3} + result_spmd{4} );
% Display the answer
fprintf("The integral of x^2 is %f arbituary units\n\n",result_total);
toc

% This is the funtion you will be integrating (y=x^2)
function y = Function_to_Integrate(x)
y = x*x;
end




More answer...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 23:43


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.