How can I plot a function containing an integral ?

2 views (last 30 days)
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

Accepted Answer

darova
darova on 20 Feb 2021
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')

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!