Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % v?nster n=200
- n=200;
- a=0; b=3;
- f=@(x)x.*sin(x);
- x=linspace(a,b,n+1);
- h=(b-a)/n;
- q=sum(h*f(x(1:n)));
- result = -1*(q- (sin(3)-3*cos(3)))
- %% v?nster n=50
- n=50;
- a=0; b=3;
- f=@(x)x.*sin(x);
- x=linspace(a,b,n+1);
- h=(b-a)/n;
- q2=sum(h*f(x(1:n)));
- result2 = -1*(q2- (sin(3)-3*cos(3)))
- %% trapets 50a=0;
- a=0;
- b=3;
- n=50;
- h=(b-a)/n;
- sum=0;
- f=@(x) x.*sin(x);
- for i=1:1:n-1
- sum= sum + f(a+i*h);
- end
- result = h/2*(f(a)+f(b)+2*sum)
- resultfel = (sin(3)-3*cos(3)) - result
- %% trapets 200
- a=0;
- b=3;
- n=200;
- h=(b-a)/n;
- sum=0;
- f=@(x) x.*sin(x);
- for i=1:1:n-1
- sum= sum + f(a+i*h);
- end
- result2 = h/2*(f(a)+f(b)+2*sum)
- %% 1b.1
- n=50;
- a=0; b=1;
- f=@(x)x.*cos(x);
- x=linspace(a,b,n+1);
- h=(b-a)/n;
- q2=sum(h*f(x((1:n))))
- %% 1b.2
- n=50;
- fun=@(x,y)x.*cos(x);
- h = 1/n;
- x = linspace(0,1,n+1);
- y = linspace(0,1,n+1);
- int=0.0;
- for ii=1:n
- for jj=1:n
- int=int+h^2*fun(x(ii)+h/2,y(jj)+h/2);
- end
- end
- %% 1c
- fun = @(x) x.*cos(x);
- yess = integral(fun,0,6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement