Question

1. Numerical Integration The integral of a function f(x) for a s x S b can be interpreted as the area between the f(x) curve
2) If you complete task 1) and get the same answer, now you are ready to move to the step 2). Now add more code to the code y
1. Numerical Integration The integral of a function f(x) for a s x S b can be interpreted as the area between the f(x) curve and the x axis, bounded by the limits x- a and x b. If we denote this area by A, then we can write A as A-f(x)dx A sophisticated method to find the area under a curve is to split the area into trapezoidal elements. Each trapezoid is called a panel. 1.2 0.2 1.2 13 20 22 24 2.4 In Monday's lecture, we discussed about how to program in MATLAB with given number of trapezoids. (See lecture slides on blackboard.) The algorithm can be summarized as below: n gets initial value calculate dx based on n calculate the area from 1t to n'h trapezoid calculate each trapezoid area find the total area find the truncation error In today's lab, we are going to practice numerical method for integration. I The first task is to write a MATLAB function to compute the integral A sin)dx using the 2.6 number of intervals n 8 (which would make dK100.2), the trapezoidal rule will return A- 1.3925. The exact solution is A = 1.3972. 2.6-1.0
2) If you complete task 1) and get the same answer, now you are ready to move to the step 2). Now add more code to the code you wrote, to calculate the integral A as a function of the number of trapezoids. Generate a plot of the truncation error as a function of n, for n 1,2,4, 8, 16, 32, 64, 128.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

clc
clear all
n = 8;
x = [];
x(1) = 1;
x(n) = 2.6;
f =@(x) sin(x);
dx = ( x(n) - x(1) )/n;
sum = 0;
dI = 0;
for i = 1:n
x(i+1) = x(i) + dx;
sum = sum + 0.5 * dx * ( f(x(i)) + f(x(i+1)));
end
disp('Trapezoidal rule returns');
fprintf('Area under cureve = %6.4f\n', sum);

syms x
f1 = sin(x);
area = int(f1,x,1,2.6);
area = abs(double(area));
fprintf('Area under cureve = %6.4f\n', area);

Add a comment
Know the answer?
Add Answer to:
1. Numerical Integration The integral of a function f(x) for a s x S b can be interpreted as the ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT