How can I plot a function containing an integral ?

2 Ansichten (letzte 30 Tage)
Diego San Roman
Diego San Roman am 19 Feb. 2021
Kommentiert: Diego San Roman am 20 Feb. 2021
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

Akzeptierte Antwort

darova
darova am 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')

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by