5-point Gaussian Quadrature using constructed approximant in Matlab

Click For Summary
SUMMARY

The discussion focuses on implementing a 5-point Gaussian Quadrature using a constructed approximant in MATLAB for a homework problem. The user successfully solved part a and problem 3.8 but encountered an error related to an undefined variable 'Exp' when executing the function. The Gaussian Quadrature was attempted with both 20 and 5 nodes, leading to confusion regarding the correct number of nodes required. Additionally, an installation error related to the CompEcon Toolbox was reported, despite the toolbox being installed correctly.

PREREQUISITES
  • Understanding of Gaussian Quadrature methods
  • Familiarity with MATLAB programming and function definitions
  • Knowledge of the CompEcon Toolbox for MATLAB
  • Basic concepts of numerical integration
NEXT STEPS
  • Review MATLAB function definitions and variable scope
  • Learn about the CompEcon Toolbox installation and troubleshooting
  • Investigate the differences between using 5 nodes and 20 nodes in Gaussian Quadrature
  • Explore the implementation of the 'broyden' method in MATLAB for solving equations
USEFUL FOR

Students and researchers in numerical analysis, MATLAB programmers, and anyone working with Gaussian Quadrature for numerical integration tasks.

woolley
Messages
3
Reaction score
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
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!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
20K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
4
Views
7K