Trapezoidal rule for integral function
3 views (last 30 days)
Show older comments
I need to apply trapezoidal rule for this Function and put it inside that tanh
: F=1-b*integral{K(s) v(x+s)}+d*integral{K(s) ur(x+s)} where K(s)=1/0.01*sqrt(2pi)*exp-s^2*/2*sigma^2 where a=0, b=1. i got error because of array. see the attached please
0 Comments
Accepted Answer
Walter Roberson
on 11 Sep 2022
x=xl:dx:xr;
That is a numeric vector, that is not integers
K(x)=1/(0.05*sqrt(2*pi))*exp(-0.5*(x/0.05).^2);
y(x)= b*K(x)*v+d*K(x)*ur;
x is a numeric vector that is not integers. K is not defined at that point, so K(x) on the left side means that you are creating a variable and indexing it at those non-integer locations, which is an error.
You appear to trying to define a formula for K and y. In MATLAB, in order to define a formula using the syntax you are using, the indexing variable on the left needs to be a symbolic variable created with sym() or syms()
The non-symbolic way to define a formula in MATLAB is to use anonymous functions. That would look like
K = @(x) 1/(0.05*sqrt(2*pi))*exp(-0.5*(x/0.05).^2);
y = @(x) b*K(x)*v+d*K(x)*ur;
6 Comments
Torsten
on 12 Sep 2022
According to the error message, your call to trapz is
I = trapz(ynum,xnum);
This is wrong. The input arguments must be reversed:
I = trapz(xnum,ynum);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!