Question
matlab help plz
Overview: In this exercise, you will write code to compare how two different mumerical methods (a middle Riemann sum, and MAT
0 0
Add a comment Improve this question Transcribed image text
Answer #1

integrals.m

F e (x) x.^2; SEnter the desired function x0 0 xl 1 N = 100 [Area_R,Area_I,E] = areal (F, x0,xl,N); fprintfArea_Reimann = %.

F =@(x) x.^2; %Enter the desired function
x0 = 0; %lower limit
x1 = 1; %upper limit
N = 100; %No. of Rectangles
[Area_R,Area_I,E] = area1(F,x0,x1,N);
fprintf('Area_Reimann = %.4f\n',round(Area_R,4));
fprintf('Area_Integral = %.4f\n',round(Area_I,4));
fprintf('Error = %s\n',sprintf('%.4e\t',E));

area1.m

|function [Area_Reimann, Area_integral, Error] h= (b-a)/N Area Reimann-0.0; ci-linspace (a+h/2,b-h/2,N); yFunc (ci) Area_Reim

function [Area_Reimann,Area_integral,Error] = area1(Func,a,b,N)
h=(b-a)/N;
Area_Reimann=0.0;
ci=linspace(a+h/2,b-h/2,N);
y=Func(ci);
Area_Reimann = h*sum(y);
Area_integral = integral(Func,a,b);
Error = Area_integral - Area_Reimann;
end

OUTPUT:

for N=10(Change the value of N in integrals.m):

Area Reimann = 0.3325 Area Integral = 0.3333 Error 8.3333e-04

for N=100

Area Reimann = 0.3333 Area_Integral = 0.3333 Error 8.3333e-06

Add a comment
Know the answer?
Add Answer to:
matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a mi...
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
  • Need help with MATLAB, what code should be added to print the graph of the trapezoid rule code be...

    Need help with MATLAB, what code should be added to print the graph of the trapezoid rule code below? %%Matlab code for Question 5. syms X y intlx exp(x),0,2); %integration of x*exp(x) fprintf("htlntegration of x"2*exp(x) for [O 3] is %2.5f.\n,y) %Integration using Trapizoidal rule nn [100 1000]; for ii 1:2 a:0; b-3; %Integration limit ns-1:nn(i) integral Values-zeros(size(ns)); ourFunction-@(x) x.*2.*exp(x); for n-ns val(n)-trapizoidal (ourFunction,a,b,nn(i); end fprintf nlntegration of x 2*exp(x) using Trapizoidal rule for [O 3]\n') fprintf('1tTrapizoidal integration value for n-%d...

  • THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

    THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...

  • MatLab Help!! Write a function called Difference to calculate the central difference, forward diflerence, and backward diference approximation to an function within a given range of xmin:xinc:xmax...

    MatLab Help!! Write a function called Difference to calculate the central difference, forward diflerence, and backward diference approximation to an function within a given range of xmin:xinc:xmax The input argument of the function Difference is the handle to an anonymous function, a row array xmin:xinc:xmax The differences should be returned as a row array, calculated at xmin xinc xmax Restriction. The function should not use loops Ex func - (x) x.3 xmin-3 xinc-e.25; xmax-4; [backDifference, centralDifference, forwardDifference] Derivative(func, xmin, xmax,...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • Overview: In this exercise, you will be writing a function that finds what spring constant k...

    Overview: In this exercise, you will be writing a function that finds what spring constant k is required in order to minimise the RMSE of a spring stiffness test. To find the spring constant k_best that minimizes RMSE, you will need to apply MATLAB's in-built function fminsearch and the function rmse (data,k) defined in Exercise 3. You do not have to code this function yourself here. This function is provided to you in AMS and can be called as rmse...

  • Hello These are a math problems that need to solve by MATLAB as code Thank you...

    Hello These are a math problems that need to solve by MATLAB as code Thank you ! Initial Value Problem #1: Consider the following first order ODE: dy-p-3 from to 2.2 with y() I (a) Solve with Euler's explicit method using h04. (b) Solve with the midpoint method using h 0.4. (c) Solve with the classical fourth-order Runge-Kutta method using 0.4 analytical solution of the ODE is,·? solution and the numerical solution at the points where the numerical solution is...

  • Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you...

    Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you 5. In this problem we will investigate using the Secant Method to approximate a root of a function f(r). The Secant Method is an iterative approach that begins with initial guesses , and r2. Then, for n > 3, the Secant Method generates approximations of a root of f(z) as In-1-In-2 n=En-1-f (x,-1) f(Fn-1)-f(-2) any iteration, the absolute error in the approximation can be...

  • 1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear syst...

    1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear system A b (A is a square nonsingular matrix) using Jacobi and Gauss-Seidel algorithms. Do not use the built-in Matlab functions for solving linear systems (a) Write a Matlab function called Jacobi that consumes a square n x n matrix A, and an n x 1 vector b, and uses the Jacobi technique to solve the system Ax-b, starting with the zero...

  • i BOX Number- " Parts reference Text CommentsHeader&Footer Links MATLAB Lab 8 This exercise was done previously for a full circle. Perform all the steps shown including the plot, but only...

    i BOX Number- " Parts reference Text CommentsHeader&Footer Links MATLAB Lab 8 This exercise was done previously for a full circle. Perform all the steps shown including the plot, but only for the function shown in part b). Objective: In calculus, integration allows us to find the area under a curve. Numerical methods exist which enable us to approximate the area An interesting approach is to randomly select points in an x-y plane and find the fraction of those points...

  • Can you please write this code in different way because this is for my friend and i want to chang...

    can you please write this code in different way because this is for my friend and i want to change it to submit it other wise we both will get zero i attached also the question down also i am not sure of his answers so just try to solve it and your trial will be so apprciated anyway thanks for your time and efforgts :- the question was From Maxwell's equations we have, 0B From this expression, we need...

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