Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

By Octave, Who can help me? (100 pts.) At the command line enter pkg load symbolic, syms x, format long and follow the instructions below

By Octave, Who can help me?

image text in transcribedimage text in transcribed

(100 pts.) At the command line enter pkg load symbolic, syms x, format long and follow the instructions below to write m-files implementing the composite Left- and Right-endpoint Rule, the composite Midpoint Rule, the composite Trapezoidal Rule, and the composite Simpson's Rule. When it is ready, run it using the parameters specified in Part 5 below and drop your four m-files and a properly-named diary file in Moodle. 1. Write an m-file which will implement both the composite Left- and Right endpoint Methods. The inputs are a symbolic function f, the left endpoint a and right endpoint b of the integration interval, the number of subintervals n, and a binary variable LR whose values (0 or 1) will determine which of the Left- or Right-endpoint Method will be used. The output is the approximate value of f(x) dx. (a) After the function definition line, create a vector of tx's starting with a, b-a incrementing by Ax:= -, and terminating with b (this last condition should be automatically satisfied). After you get the program running, check to make sure you have n +1 values in the vector t. Note that the first value in the vector is denoted t(1) but in the text the notation is Xo. Be aware of this index shift when you write your code. (b) Assign fh to be a function handle of f. (c) Next create a for-loop to evaluate f at each tk: fx(k)=fh(t(k)); (d) If LR==0 sum fx(1:w-1) and multiply by Ax to assign the output, oth- erwise sum fx(2:w) and multiply by Ax to assign the output. 2. Next write a new m-file which implements the composite Midpoint Method. (a) Again create a vector of ti's, but start with a+Ax/2 and increment by Ab-a Au: ", terminating with b. Once the program is running check to be sure you have n, not n +1, values in the vector t. (b) Assign fh to be a function handle of f. (c) Next create a for-loop in which f is evaluated at each tk. (a) Sum the vector fx, multiply by Ar and assign the result to the output. 3. Now write a new m-file which implements the composite Trapezoid Method. (a) Create a vector of th's as in the Left- and Right-endpoint routine. (b) Assign fh to be a function handle of f. (c) Create a for-loop in which f is evaluated at each tk. (d) Sum the vector 2*fx(2:end-1), add fx(1) and fx(end), multiply by Ax and assign the result to the output. 4. Finally, write a new m-file which implements the composite Simpson's Method. (a) Create a vector of th's as in the Left- and Right-endpoint routine. (b) Ensure that n is even by including an if statement and if n is odd, use return to exit the routine. (c) Assign fh to be a function handle of f. (a) Create a for-loop in which f is evaluated at each tk. (e) Figure out how to create the sum in the composite Simpson's Method. Expressions like fx(2:2:end-1) will be useful. Multiply by Ac and assign the result to the output as usual. 5. Test each of your routines as follows: (a) Test all on f(x) = (x - y) on (-3,3] with n = 100. To avoid the warn- ing about passing floating-point values to sym, use f=(x-sym(1)/2)^2. (b) Test Simpson's on f(x) = (- 1)' on (-3, 3) with n = 2 and n = 99. (c) Test Trapezoid on f(x) = 7:- 1 on [-3, 3) with n = 100 and n=2. (a) Test Simpson's on f(x) = sin r on (0,7] with n = 2 and n = 200. (100 pts.) At the command line enter pkg load symbolic, syms x, format long and follow the instructions below to write m-files implementing the composite Left- and Right-endpoint Rule, the composite Midpoint Rule, the composite Trapezoidal Rule, and the composite Simpson's Rule. When it is ready, run it using the parameters specified in Part 5 below and drop your four m-files and a properly-named diary file in Moodle. 1. Write an m-file which will implement both the composite Left- and Right endpoint Methods. The inputs are a symbolic function f, the left endpoint a and right endpoint b of the integration interval, the number of subintervals n, and a binary variable LR whose values (0 or 1) will determine which of the Left- or Right-endpoint Method will be used. The output is the approximate value of f(x) dx. (a) After the function definition line, create a vector of tx's starting with a, b-a incrementing by Ax:= -, and terminating with b (this last condition should be automatically satisfied). After you get the program running, check to make sure you have n +1 values in the vector t. Note that the first value in the vector is denoted t(1) but in the text the notation is Xo. Be aware of this index shift when you write your code. (b) Assign fh to be a function handle of f. (c) Next create a for-loop to evaluate f at each tk: fx(k)=fh(t(k)); (d) If LR==0 sum fx(1:w-1) and multiply by Ax to assign the output, oth- erwise sum fx(2:w) and multiply by Ax to assign the output. 2. Next write a new m-file which implements the composite Midpoint Method. (a) Again create a vector of ti's, but start with a+Ax/2 and increment by Ab-a Au: ", terminating with b. Once the program is running check to be sure you have n, not n +1, values in the vector t. (b) Assign fh to be a function handle of f. (c) Next create a for-loop in which f is evaluated at each tk. (a) Sum the vector fx, multiply by Ar and assign the result to the output. 3. Now write a new m-file which implements the composite Trapezoid Method. (a) Create a vector of th's as in the Left- and Right-endpoint routine. (b) Assign fh to be a function handle of f. (c) Create a for-loop in which f is evaluated at each tk. (d) Sum the vector 2*fx(2:end-1), add fx(1) and fx(end), multiply by Ax and assign the result to the output. 4. Finally, write a new m-file which implements the composite Simpson's Method. (a) Create a vector of th's as in the Left- and Right-endpoint routine. (b) Ensure that n is even by including an if statement and if n is odd, use return to exit the routine. (c) Assign fh to be a function handle of f. (a) Create a for-loop in which f is evaluated at each tk. (e) Figure out how to create the sum in the composite Simpson's Method. Expressions like fx(2:2:end-1) will be useful. Multiply by Ac and assign the result to the output as usual. 5. Test each of your routines as follows: (a) Test all on f(x) = (x - y) on (-3,3] with n = 100. To avoid the warn- ing about passing floating-point values to sym, use f=(x-sym(1)/2)^2. (b) Test Simpson's on f(x) = (- 1)' on (-3, 3) with n = 2 and n = 99. (c) Test Trapezoid on f(x) = 7:- 1 on [-3, 3) with n = 100 and n=2. (a) Test Simpson's on f(x) = sin r on (0,7] with n = 2 and n = 200

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions