How can I solve the problem in integral code?

1 回表示 (過去 30 日間)
Shreen El-Sapa
Shreen El-Sapa 2025 年 5 月 12 日
編集済み: Torsten 2025 年 5 月 13 日
Solve the problem

採用された回答

Torsten
Torsten 2025 年 5 月 12 日
編集済み: Torsten 2025 年 5 月 12 日
Loop over the values of the sigma-vector - thus call "vpaintegral" for each sigma value separately.
Or alternatively make your code a function and call it from a script with a single sigma-value as input.
Further, I'd recommend first to use "integral" instead of "vpaintegral" to save computation time.
And where do you compute w1 - w6 - the variables you try to plot at the end of your code ?
Works because "vpaintegral" is called for each sigma-value separately:
syms r
f = r^2;
sigma = 0:0.1:1;
arrayfun(@(sigma)vpaintegral(f,r,0,sigma),sigma)
ans = 
Does not work because "vpaintegral" is called once with the complete sigma-vector:
syms r
f = r^2;
sigma = 0:0.1:1;
vpaintegral(f,r,0,sigma)
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.

Error in sym/vpaintegral (line 182)
(isinf(b) && isempty(symvar(b)) && ~isreal(b))
  8 件のコメント
Walter Roberson
Walter Roberson 2025 年 5 月 12 日
Note that vpaintegral() can handle the case where the part to be integrated is non-scalar, but cannot handle the case where the limits to integration are non-scalar.
syms x
vpaintegral([sin(x), cos(x)], x, [0 1])
ans = 
Torsten
Torsten 2025 年 5 月 13 日
編集済み: Torsten 2025 年 5 月 13 日
Thank you for the info.
So the changes to your last code (test_microstrength.m) were not necessary (except for the final plotting).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by