Quadrature, midpoint
조회 수: 5 (최근 30일)
이전 댓글 표시
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
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.
답변 (1개)
Matt Tearle
2011년 3월 15일
A few things right off the bat:
- syntax error in your for-loop
- you don't need a for-loop -- just make a vector of the x points using the range operator (:)
- 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.
- ( EDIT to add:) To do parts (b)-(d) of the question, write a script that makes a vector of h values;
- 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;
- At the end of the loop, you should have a vector h and a corresponding vector err; use the appropriate semilog* function to plot.
- 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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!