Plotting integral over an interval
5 ビュー (過去 30 日間)
古いコメントを表示
I want to integrate the following over the interval x0 = 0:2:8
. I have tried using arrayfun:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/228284/image.png)
x0 = 0:2:8;
cai= @(theta) ((4.*pi.*x0.*cos(theta).*sin(theta)+8.*pi.*cos(theta).*cos(theta).*sin(theta))./(1+0.5.*x0+cos(theta)));
xval = arrayfun(@(uplim) integral(cai, 0, uplim, 'ArrayValued',true), x0);
plot(x0, xval)
grid
But I got the following error code:
Error using arrayfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in PlottingFx (line 6)
xval = arrayfun(@(uplim) integral(cai, 0, uplim, 'ArrayValued',true), x0);
Can anyone help me?
0 件のコメント
採用された回答
infinity
2019 年 7 月 9 日
Hello,
The way you try to plot the integral may be not correct, for x0 you can compute the integral by using the integral fuction with repsect to theta. This code below may help you understand this well
x0 = 0:2:8;
cai= @(theta) ((4.*pi.*x0.*cos(theta).*sin(theta)...
+8.*pi.*cos(theta).*cos(theta).*sin(theta))...
./(1+0.5.*x0*cos(theta)));
xval = integral(cai, 0, pi,'ArrayValued',true);
plot(x0, xval)
grid
Also, I fix an mismatch between your code and your provided function
In your code:
./(1+0.5.*x0+cos(theta)));
I change it to
./(1+0.5.*x0*cos(theta)));
which is correct with your given equation.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!