Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- disp("------------------------Simpson's 3/8th Rule------------------------")
- % str = input('Give an equation in x: ','s') ;
- % a = input('Enter lowerbound value:');
- % a
- % b = input('Enter upperbound value:');
- % b
- str = "exp(1)"
- a=-1;
- b=1;
- a
- b
- h = (b-a)/3;
- x1 = a + h;
- x2 = a + h + h;
- h
- % f = inline(str,'x') ;
- f = str2func(['@(x) ',str]);
- fa = feval(f,a) ;
- fb = feval(f,b) ;
- fx1 = 3* feval(f, x1) ;
- fx2 = 3* feval(f, x2) ;
- I = (h/2)*(fa+fx1+fx2+fb);
- disp(['Ans: ', num2str(I)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement