How can I plot a function containing an integral ?

1 回表示 (過去 30 日間)
Diego San Roman
Diego San Roman 2021 年 2 月 19 日
コメント済み: Diego San Roman 2021 年 2 月 20 日
Hey there !
I'm pretty new to Matlab and want to plot a function containing an integral.
The function I want to plot is :
f(s) = 1.05274*exp(integral((0.03-0.000569*exp(0.0824*(s-25))-0.0262139)/2.08773))
with the integral going from value 25 to the value of s.
For that,
1) I first define the X-axis as a vector :
s = linspace(20,100,100)
2) I then define the term inside the integral i.e. (0.03-0.000569*exp(0.0824*(s-25))-0.0262139)/2.08773
fun_a = @(s) (0.03-0.000569*exp(0.0824*(s-25))-0.0262139)/2.08773
3) I define the function f(s)
f = 1.05274*exp(integral(fun_a,25,s))
However, Matlab states "Error using integral (line 85)
A and B must be floating-point scalars." after I input step 3.
Since s is a vector and not a scalar, it doesn't allow me to compute the integral (because the integral is defined from 25 to s)
I just want to tell Matlab that at the X-axis value s=20 for example, I want the function f(s) stated above to take its value for s=20. And this for all values of s between 20 and 100.
Once I have the function, I just want to plot it, with f(s) being the Y-axis and s being the X-axis.
Thank you very much !
Best,
Diego

採用された回答

darova
darova 2021 年 2 月 20 日
I suggest you to use numerical approach - cumtrapz
clc,clear
x = linspace(1,15,100);
f = 2*x;
sf = cumtrapz(x,f);
plot(x,f)
line(x,sf)
line(x,x.^2+5)
legend('original 2x','cumtrapz x^2','x^2')
  1 件のコメント
Diego San Roman
Diego San Roman 2021 年 2 月 20 日
Worked like a charm. Thanks !

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by