Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. % v?nster n=200
  2. n=200;
  3. a=0; b=3;
  4. f=@(x)x.*sin(x);
  5. x=linspace(a,b,n+1);
  6. h=(b-a)/n;
  7. q=sum(h*f(x(1:n)));
  8. result = -1*(q- (sin(3)-3*cos(3)))
  9. %% v?nster n=50
  10. n=50;
  11. a=0; b=3;
  12. f=@(x)x.*sin(x);
  13. x=linspace(a,b,n+1);
  14. h=(b-a)/n;
  15. q2=sum(h*f(x(1:n)));
  16. result2 = -1*(q2- (sin(3)-3*cos(3)))
  17. %% trapets 50a=0;
  18. a=0;
  19. b=3;
  20. n=50;
  21. h=(b-a)/n;
  22. sum=0;
  23. f=@(x) x.*sin(x);
  24. for i=1:1:n-1
  25. sum= sum + f(a+i*h);
  26.  
  27. end
  28. result = h/2*(f(a)+f(b)+2*sum)
  29. resultfel = (sin(3)-3*cos(3)) - result
  30.  
  31. %% trapets 200
  32. a=0;
  33. b=3;
  34. n=200;
  35. h=(b-a)/n;
  36. sum=0;
  37. f=@(x) x.*sin(x);
  38. for i=1:1:n-1
  39. sum= sum + f(a+i*h);
  40.  
  41. end
  42. result2 = h/2*(f(a)+f(b)+2*sum)
  43. %% 1b.1
  44. n=50;
  45. a=0; b=1;
  46. f=@(x)x.*cos(x);
  47. x=linspace(a,b,n+1);
  48. h=(b-a)/n;
  49. q2=sum(h*f(x((1:n))))
  50. %% 1b.2
  51. n=50;
  52. fun=@(x,y)x.*cos(x);
  53. h = 1/n;
  54. x = linspace(0,1,n+1);
  55. y = linspace(0,1,n+1);
  56. int=0.0;
  57. for ii=1:n
  58. for jj=1:n
  59. int=int+h^2*fun(x(ii)+h/2,y(jj)+h/2);
  60. end
  61. end
  62. %% 1c
  63. fun = @(x) x.*cos(x);
  64. yess = integral(fun,0,6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement