how to evaluate definite integral

3 ビュー (過去 30 日間)
az
az 2019 年 12 月 5 日
コメント済み: az 2019 年 12 月 5 日
Could anyone please help to find wat is wrrong here in the f ?
Thanks
ho= 2;
ep = 0.0:0.01:0.1;
% ep = 0.02;
L = 3;
q = 14.4;
mu = 10^8;
X = 2 * pi * x /L;
f = @(X) 1./(ho(1 + (ep .* sin(X))))^3;
P = integral(f,0,L);
% Fvpaint = vpaintegral(f,X,[0 L])
pr = - 3/2 *mu *q * P
plot ( ep, pr)

採用された回答

Walter Roberson
Walter Roberson 2019 年 12 月 5 日
Your ep is 1 x 11 so for each scalar x your f would want to return 1 x 11. integral() does not expect that: integral() expects that for a scalar x, the function would return a scalar. You can use the 'arrayvalued' option to integral to permit a vector to be returned.
However if you do that, then note you overwrite all of P each iteration of the for loop. You could switch to assigning to P(i) but then you would have the problem that that would be a scalar location. So you would need to assign to P(i,:) . But then you have
pr(i) = - (3/2) .* mu .*q .* P
which is outside the loop and would try to assign P to the scalar location pr(i) where i has the last value it was assigned, which would be length(ep) . With P being a 2D array, assigning to a scalar location pr(i) is not going to do well. And then you should have another look at what you are plot()'ing.
It is an odd coincidence that you loop to length(ep) and that you are producing a vector of length(ep) in each iteration.
I would suggest that at the very least you should be changing
f = @(x) 1./(ho*(1 + (ep .* sin(2 * pi * x /L)))).^3;
to
f = @(x) 1./(ho*(1 + (ep(i) .* sin(2 * pi * x /L)))).^3;
If you do that then a bunch of what I said does not apply any more... but the part about overwriting all of P on each iteration does.
  1 件のコメント
az
az 2019 年 12 月 5 日
Thank you Mr Roberson. It works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by