Question

Create two vectors with entries evenly spaced between 0 and pi. One vector should be of...

  • Create two vectors with entries evenly spaced between 0 and pi. One vector should be of length 100 and the other should be of length 1000. Then apply these vectors to the function sin(2x).
  • Now use cumsum and cumtrapz to approximate the integral of sin(2x). Do this for both lengths as before.
  • Subtract 0.5 from every element of each integral vector to center their graphs at 0. Then compare the computed vectors with the analytic antiderivative as before. Return the magnitude of the max error for each of the four cases.
  • Plot the best approximation for the integral. Add a title to the plot
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

clc%clears screen
clear all%clears history
close all%closes all files
x1=linspace(0,pi,100);
x2=linspace(0,pi,1000);
y1=sin(2*x1);
y2=sin(2*x2);
Ia1=2*cos(2*x1);
Ia2=2*cos(2*x1);
disp('Integral for first');
I1=cumtrapz(x1,y1)
disp('Integral for second');
I2=cumtrapz(x2,y2)
disp('Max error is first is');
max(abs(I1(:)-Ia1(:)))
disp('Max error is second is');
max(abs(I2(:)-Ia2(:)))
plot(x2,I2);
title('Plot for 1000 points');

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Create two vectors with entries evenly spaced between 0 and pi. One vector should be of...
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
  • My code for calculating the first derivative is the second image Compute second derivative O solutions...

    My code for calculating the first derivative is the second image Compute second derivative O solutions submitted (max: 10) You are provided with a set of data for the position of an object over time. The data is sampled at evenly spaced time intervals. Your task is to find a second order accurate approximation for the acceleration at each point in time. Write a Matlab function that takes in a vector of positions x, the time interval between each sampled...

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