Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function I = simpson(a,b,n)
  2. deff('y=f(x)','y=x^4')
  3. h=(b-a)/n
  4. suma1=0
  5. suma2=0
  6. suma3=0
  7. for i=0:n
  8. x=a+i*h
  9. y=f(x)
  10. disp([x y])
  11. if (i==0)|(i==n) then
  12. suma1=suma1+y
  13. else if (modulo(i,3)==0) then
  14. suma2=suma2+y
  15. else
  16. suma3=suma3+y
  17. end
  18. end
  19. end
  20. I=((3*h)/8)*(suma1+2*suma2+3*suma3)
  21. endfunction
  22.  
  23. a=input("Ingresa Limite Inferior: ")
  24. b=input("Ingresa Limite Superior: ")
  25. n=input("Ingresa numero de intervalos: ")
  26. if modulo(n,3) == 0 then
  27. disp(simpson(a,b,n),"El resultado de integrar usando la regla de simpson 3/8 es:")
  28. else
  29. disp("Tu numero de intervalos no es divisible por 3")
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement