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