Question

Complete the following problems in Matlab environment. Copy your com mand and final answer from MATLAB command window and pasCode your own MATLAB program to find the approximate value of the integral J e dr with Trapezoidal rule for N 20, .e., 2 (for

Complete the following problems in Matlab environment. Copy your com mand and final answer from MATLAB command window and paste them in a word document. Submit a single word document file for the entire HW Problems:
Code your own MATLAB program to find the approximate value of the integral J e dr with Trapezoidal rule for N 20, .e., 2 (formula 4.21 on Page 201 YS). Also give the relative error of t2o with de-1. (Hint: For-end loops or Elementwise operations)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Problem:

f = @(x) exp(x);% Function to integrate

N = 20;% Number of trapezoids
a = 0;% Lower limit
b = 2;% Upper limit

%% Trapezoidal Rule
h = abs((b - a)/N);
sum = 0;
for i = 1:(N-1)
    x = a + i * h;
    sum = sum + f(x);
end
approxValue = (h/2) * (f(a) + 2 * sum + f(b));

trueValue = exp(2) - 1;
relativeError = (approxValue - trueValue)/trueValue;

fprintf('Approximate value = %f\n', approxValue);
fprintf('True value = %f\n', trueValue);
fprintf('Relative error = %f\n', relativeError);

OUTPUT:
Editor -CAUsers1 Shubhamlpractice.m practice.m ×1+ f = @ (x) exp(x);% Function to integrate N = 20;% Number of trapezoids a =

Add a comment
Know the answer?
Add Answer to:
Complete the following problems in Matlab environment. Copy your com mand and final answer from MATLAB command window a...
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
  • Solve the following problems in the MATLAB Command Window. Show all of your work and add...

    Solve the following problems in the MATLAB Command Window. Show all of your work and add comments to distinguish each problem. Include your name as a comment at the top of the MATLAB Command Window. Copy the solutions from the MATLAB Command Window into Microsoft Word. Submit your Microsoft Word file in Blackboard by the due date. 1. (5-20/7+2.53)2 2. 6 x 3.1+ 120/5-155/3 3. 8+80/2.6+ e3.5 4. [sin(0.2T)]/[cos(n/6)] + tan 72° 5. Set t-3.2 and evaluate 0.5e3t+3.82t3 6. Define...

  • MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS....

    MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS. THE PROGRAM TO BE MODIFIED IS THE NEXT ONE: clc clear % Approximate the value of e ^ x using the Taylor Series x = input( 'Enter the value of x for e^x. x = ' ); t = input( 'Enter the amount of desired terms. t = ' ); i = 1; e_taylor = 0; % initializing the variable for the accumulator while...

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