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

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);

답변 (2개)

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

댓글 수: 10

it says code ran without an out put.
i dont know why it doesnt work.
hey KSSV it didn't work do you have any other solutions please??
thank you
Change the line:
k =abs(x).*exp(-x).^2 ;
to
k =abs(x).*exp(-x.^2) ;
I got K value as 0.99987.
a=-3;
b=3;
h =(b-a)/N;
x=a:h:b;
k = abs(x).*exp(-x.^2) ;
K =sum(k*h);
this is what i did and it says code ran without output.
What do you mean by ran without output?

댓글을 달려면 로그인하십시오.

What is "the above technique"?
Try using trapz() instead of sum.

댓글 수: 7

this is the technique we have to use, the (trapz) didn't work.
trapz is not going to agree with the required summation; the endpoints are handled differently.
trapz is effectively
so if i want to write the third equation, (K), wouldnt it be
k = abs(x).*exp(-x.^2) ;
K =sum(k*h);
how do i write that? i don't know why KSSV gave me that answer.
uh my bad i gave different question sorry KSSV

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2020년 5월 27일

댓글:

2020년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by