Hi guys ,(adsbygoogle = window.adsbygoogle || []).push({});

I need to write a code in order to calculate Simpson's Rule.

Here is my code , what's wrong with it ?

Here is the link to the actual formulaPHP:function [integral]=simp(f,a,b,n)

if mod(n,2)~=0

warning('n must be even!')

else

h=(b-a)/n;

integral=0;

for i=1:1:n-1

x=a+i*h;

if (mod(i,2)==0)

integral=integral+2*eval(f);

else

integral=integral+4*eval(f);

end

end

x=a;

integral=integral+eval(f);

x=a+n*h;

integral=integral+eval(f);

integral=(h/3)*integral;

end

"[URL [Broken]

Thanks a lot :)

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# A problem in Matlab ,code doesn't work

Loading...

Similar Threads - problem Matlab code | Date |
---|---|

Does anyone had this plotting problem with MATLAB? | Dec 23, 2017 |

Matlab map representation problems | Feb 11, 2017 |

Matlab code problem | Nov 15, 2013 |

Matlab coding problem (Black-Scholes Option Pricing content) | Feb 13, 2011 |

Matlab code for transient 2 D thermal problem | Mar 13, 2007 |

**Physics Forums - The Fusion of Science and Community**