# hello how do I write this function without getting an error saying "variable K has an incorrect value".

1 view (last 30 days)
Reza Ghasemi on 27 May 2020
Commented: Reza Ghasemi on 28 May 2020 my code is: And so far only the (K) is wrong.
N = 1000;
a= 0;
b= pi;
h = (b-a)/N;
x=a:h:b;
f = x.^2.*sin(x);
F = sum(f*h );
a= 1;
b= 2;
h = (b-a)/N;
x=a:h:b;
g =(x.^3.2 + 2.*x.^2.22 +x + 21) ;
G = sum(g*h) ;
a=-3 ;
b= 3;
h = (b-a)/N;
x=a:h:b;
k =abs(x).*exp(-x).^2 ;
K = sum(k*h);

KSSV on 27 May 2020
a=-3 ;
b= 3;
h = (b-a)/N;
x=a:h:b;
k =abs(x).*exp(-x.^2) ;
K = sum(k*h);

Reza Ghasemi on 27 May 2020
the output i meant
Reza Ghasemi on 27 May 2020 Reza Ghasemi on 27 May 2020
these are the errors i get

Image Analyst on 27 May 2020
What is "the above technique"?
Try using trapz() instead of sum.

Walter Roberson on 28 May 2020
No, K = which is not the same as Reza Ghasemi on 28 May 2020
how do i write that? i don't know why KSSV gave me that answer.
Reza Ghasemi on 28 May 2020
uh my bad i gave different question sorry KSSV