interp2 interpolating in one dimension??

조회 수: 6 (최근 30일)
J
J 2012년 7월 7일
Hi,
I am calling interp2 inside a function of fminsearch and the vector that is returned seems to be interpolating in one dimension as it should (answers are over the grid of [1,40]) while in the other dimension its giving values that are pretty much all at 1 even when the grid is over [1,40]. Is this a general issue that someone can give advice on how to resolve or should I paste my code for others to replicate?
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 7월 7일
Code please.
J
J 2012년 7월 7일
편집: Walter Roberson 2012년 7월 7일
main m.file
clear all;
close all;
clc;
tic
global v0 vv0 beta delta alpha eta kmat k00 s kgrid Agrid gamma r p mmat m00 mgrid pmat l
%no. of firms
J=4;
r=0.5;
% set parameters
alpha = 0.2; % capital's share
beta = 0.9;
delta = 0.1; % depreciation rate (annual)
gamma=0.2;
eta=0.5;
s = 3;
tol = 0.1;
maxits =25;
dif=tol+1000;
dif1 = tol+1000;
dif2 = tol+1000;
its = 0;
its1 = 0;
Agrid=[1,1,1,1];
kmat=meshgrid(1:1:25);
mmat=meshgrid(1:1:25);
kmat = kmat';
[JJJJ,N] = size(kmat);
mmat = mmat';
[JJJJ,N] = size(mmat);
v0 = zeros(JJJJ,N);
v1=zeros(J,N);
while dif>tol & its<maxits
for j=1:J
for i=1:N
k00=kmat(i,j);
m00=mmat(i,j);
km0=[k00,m00];
[km1,fval] = fminsearch(@(km) firmvalfn_2cap_rental_noprices(km,j),km0)%,options);
v1(i,j) = -firmvalfn_2cap_rental_noprices(km1,j);
k11(i,j) = km1(1);
m11(i,j) = km1(2);
end
end
dif=norm(v1-v0)
v0 = v1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function val=firmvalfn_2cap_rental_noprices(km,j)
% This program gets the value function of firm for a neoclassical growth model
global pmatt v0 vv0 beta delta p alpha eta k00 kgrid kmat m00 mgrid mmat s k2mat m2mat Agrid gamma ll
gg= interp2(kmat(:,j),mmat(:,j),v0,km(1),km(2),'linear');
profit = (Agrid(j)*(k00^alpha)*(m00^alpha))- (km(1)-k00*(1-delta))-(km(2)-m00*(1-delta));
if profit<=0
val = -9999999 - 999*abs(profit);
else
val= log(profit)+ beta*gg;
end
val = -val;

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by