Quadrature, midpoint

Hello and good day to you all! I'm having a little difficulty in completing the questions in the link below and would be grateful for some assistance in finding solutions.
Up to now I have come up with the following incomplete code:
function [ICMR,h]=midpoint(a,b,n)
h=(b-a)/n ;
for=i=1:n ;
m(i)=a+(i-0.5)*h ;
end
I=-((10*pi-3+3*exp(2*pi))/25/exp(2*pi));
ICMR=h*sum(I);
Now I am looking for someone to help me gain a better understanding of how to use Matlab to complete these questions. please help!!

댓글 수: 2

Jan
Jan 2011년 3월 15일
Please use the code formatting to increase the readability.
My browser can not display the Google-Docs files. It would be easier for us, if you take the time to post the question instead of the link.
Matt Tearle
Matt Tearle 2011년 3월 15일
basically "write a mid-point rule quadrature function"

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt Tearle
Matt Tearle 2011년 3월 15일

0 개 추천

A few things right off the bat:
  1. syntax error in your for-loop
  2. you don't need a for-loop -- just make a vector of the x points using the range operator (:)
  3. have the function be one of the arguments to the function, then your function values can be evaluated directly as I = f(x) (where x is the vector of points found in step 2). When you call your function, pass f in as a function handle.
  4. ( EDIT to add:) To do parts (b)-(d) of the question, write a script that makes a vector of h values;
  5. Use a for-loop to go through the values of h, apply your function, compare to the exact answer, and store the resulting error in another array;
  6. At the end of the loop, you should have a vector h and a corresponding vector err; use the appropriate semilog* function to plot.
  7. Don't forget to preallocate space for err before doing 5.
If you really want to get slick, you can replace 5 with an arrayfun call, having defined an anonymous function handle to calculate the error as a function of h.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2011년 3월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by