Subscripted assignment dimension mismatch error question

2 views (last 30 days)
Hi,
I understand that this error comes into play when vectors/matrices don't line up, but I'm not exactly sure how to fix this, as I am pretty new to Matlab. My code is below. Basically I am looking to solve a Bellman equation...I have 2 continuous action/control variables and 1 continuous state variable. The first "case" sets up the bounds of the control/action variable. The second "case" looks at the value function with the first derivatives in the respective columns and the second derivatives off the respective pages. This error I get is on "out2(:,1)=1./c;". Does anyone have any suggestions? Thank you in advance.
if
function [out1,out2,out3] = func(flag,s,x,e,alpha,c,leisure)
n = size(s,1); %returns number of rows
ds = 1; %defines number of continuous state variables
dx = 2; %defines number of continuous action/control variables
switch flag
case 'b'
out1 = zeros(size(s)); %outputs zeros for the vector "s"
out2 = s; %outputs value of "s"...cannot exceed state variable
case 'f'
out2 = zeros(n,dx); %outputs zeros for the n by dx matrix, n is scalar
out3 = zeros(n,dx,dx); %outputs zeros for the dx-th page (3 dimensions)
out1 = log(c) + alpha*log(leisure) %value function
out2(:,1) = 1./c; %first derivative wrt c
out2(:,2) = alpha./leisure %first derivative wrt leisure
out3(:,1,1) = -1./c.^2 %second derivative wrt c
out3(:,2,2) = -alpha./leisure.^2 %second derivative wrt leisure
case 'g'
out2 = zeros(n,ds,dx); %outputs zeros for page of first derivatives
out3 = zeros(n,ds,dx,dx);%outputs zeros for page of second derivatives
out1 = s - c - leisure %level of state equation
out2(:,1,2) = -ones(n,1);%derivative of state equation wrt c
out2(:,2,2) = -ones(n,1);%derivative of state equation wrt leisure
end
Thank you, Brian

Answers (1)

John Petersen
John Petersen on 14 Dec 2012
Maybe c is a row vector so it doesn't match the dimensions of out2(:,1) which is a column vector.

Categories

Find more on Elementary Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!