Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Matlab Function generators. Write a nested function that evaluates a polynomial of the form y=ax2+bx+cy=ax2+bx+c. The host function genFunc() should be able to take

In Matlab

Function generators. Write a nested function that evaluates a polynomial of the form y=ax2+bx+cy=ax2+bx+c. The host function genFunc() should be able to take varying number of arguments using varargin with maximum of 3 arguments (a,b,c) to initialize the coefficients of the polynomial. If there is only one argument, then b and c must be set to zero. If there are two input arguments, then c is set to zero. If none are given on input, then the returned function should be zero. If more than 3 arguments exist, then the function should display an error and stop. Also, if the input arguments are not real numbers, then the function should return and error and stop.

On output, the host function should create and return a function handle for the nested function evalFunc(). The nested function should calculate a value of yy for a given value of xx, using the values of aa, bb, and cc stored in the host function. This is called a function generator, since the host function generates and outputs another function that can be called and used later on in the program. Once you create your function generator, test it in the following way: Call genFunc(1,2,0) and save the output function handle in a variable, say h1. Call genFunc(1,2) and save the output function handle in a variable, say h2. Then these two function handles, should give the same result, given the same input x values.

image text in transcribed

8. Function generators. Write a nested function that evaluates a polynomial of the form | y = ax2 + bx + c. The host function genFuncO should be able to take varying number of arguments using varargin with maximum of 3 arguments (a, b,e) to initialize the coefficients of the polynomial. If there is only one argument, then b and e must be set to zero. If there are two input arguments, then e is set to zero. If none are given on input, then the returned function should be zero. If more than 3 arguments exist, then the function should display an error and stop. Also, if the input arguments are not real numbers, then the function should return and error and stop. On output, the host function should create and return a function handle for the nested function evalFunc). The nested function should calculate a value of y for a given value of x, using the values of a, b, and c stored in the host function. This is called a function generator, since the host function generates and outputs another function that can be called and used later on in the program. Once you create your function generator, test it in the following way: Call genFunc (1,2,0) and save the output function handle in a variable, say h1. Call genFunc(1,2) and save the output function handle in a variable, say h2. Then these two function handles, should give the same result, given the same input x values

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

Step: 3

blur-text-image

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

6. The cost of the training creates a need to show that it works.

Answered: 1 week ago