5-point Gaussian Quadrature using constructed approximant in Matlab

In summary, the conversation discusses a problem involving calculating the expected price and using it to solve for a value of a. The person has solved part a and problem 3.8, but is unsure if their solution for part a is correct. They also mention using a function and a routine to solve the problem, but encounter an error message. They believe that the CompEcon Toolbox is installed correctly.
  • #1
woolley
3
0

Homework Statement


6.3.b highlighted in attachment.
Have solved part a (which gives the approximant used in part b) and problem 3.8 (which gives the original function). 3.8 was definitely solved correctly. Part a could be wrong, but the solution seems OK.
a = acreage
y = yield
from 3.8 - p1,p2,c1,c2 are prices and consumption in periods 1 and 2.

Homework Equations


a = 0.5+0.5*Ey(f(ay)) where Ey is the expected price in terms of y and f(ay)=p1(s).

The Attempt at a Solution


%DEFINE FUNCTION FOR Part b
function [fval] = f63b(y)
fval = 0.5+0.5*Exp;

%5-POINT GAUSSIAN QUADRATURE
[y,w] = qnwlogn(20,0,0.01);
Exp = w'*p1;
fprintf('Exp'); disp(Exp)

a = broyden('f63b',s/2);
fprintf('a'); disp(a)

Gives value for expectation that is accurate, but then the following error:
? Undefined function or variable 'Exp'.
Cannot find solution for a! Should we have 5 nodes or 20? When change to qnwlogn(5,0,0/01) get no value for Exp.
 
Last edited:
Physics news on Phys.org
  • #2
Need to evaluate function [p1hat] = p1hat(a,y) using routine funeval(coef,fspace1,s), where s=ay. Matlab gives the following error:

If you get this message, you have not correctly installed the CompEcon Toolbox
Please read the README file for installation details, epsecially the section concerning MEX files
? Error using ==> CEtools/private/chebeval at 22

But toolbox is installed correctly!
 
  • #3


It seems that your approach to solving this problem is correct, but there are a few issues with your code.

Firstly, in your function for part b, you define the variable 'fval' but you never use it in your calculation of 'Exp'. Additionally, you are trying to use 'Exp' before it has been defined. You should first calculate 'Exp' using the provided values for 'p1' and then use it in your calculation of 'fval'.

Secondly, in your attempt at using the 5-point Gaussian Quadrature, you are using the function 'qnwlogn' which is not defined in MATLAB. Instead, you should use the function 'qnwnorm' which is specifically designed for Gaussian quadrature. Also, the first argument of the function should be the number of nodes you want to use, so it should be '5' instead of '20' or 'qnwnorm(20,0,0.01)'.

Finally, in your code for solving for 'a', you are using the function 'broyden' which is not defined in MATLAB. Instead, you can use the function 'fsolve' to find the root of your function 'f63b' and assign it to the variable 'a'. The number of nodes used for the Gaussian quadrature should also be consistent with the number used in your function 'f63b', so it should be '5' instead of '20'.

After making these changes, your code should look something like this:

%DEFINE FUNCTION FOR Part b
function [fval] = f63b(y)
fval = 0.5+0.5*Exp;

%5-POINT GAUSSIAN QUADRATURE
[y,w] = qnwnorm(5,0,0.01);
Exp = w'*p1;
fprintf('Exp'); disp(Exp)

a = fsolve('f63b',s/2);
fprintf('a'); disp(a)

I hope this helps and good luck with your homework!
 

What is 5-point Gaussian Quadrature using constructed approximant in Matlab?

5-point Gaussian Quadrature using constructed approximant in Matlab is a numerical integration method used to approximate the definite integral of a function. It involves dividing the interval of integration into 5 subintervals and using a specific set of weights and nodes to calculate the approximate value of the integral.

How does 5-point Gaussian Quadrature using constructed approximant work?

This method uses a constructed approximant, which is a polynomial function that closely approximates the original function. The integral of this approximant is then calculated using the weights and nodes, which are predetermined values. The final result is an approximation of the definite integral of the original function.

What are the advantages of using 5-point Gaussian Quadrature using constructed approximant?

One advantage is that it provides a more accurate approximation compared to other numerical integration methods. It also requires fewer function evaluations, making it more efficient for complex functions. Additionally, it can handle both smooth and non-smooth functions.

What are the limitations of 5-point Gaussian Quadrature using constructed approximant?

One limitation is that it is only accurate for functions that can be well approximated by a polynomial. It also requires prior knowledge of the function to determine the weights and nodes, which may not always be available. Additionally, it may not be suitable for high-dimensional integrals.

How can 5-point Gaussian Quadrature using constructed approximant be implemented in Matlab?

In Matlab, this method can be implemented by defining the function to be integrated, determining the weights and nodes for the specific interval, and calculating the integral using the formula. The process can be automated using loops for multiple intervals. There are also built-in functions in Matlab that can perform this integration method.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
940
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
20K
  • Programming and Computer Science
Replies
1
Views
3K
Back
Top