question 1: the demand is the sum of domestic and export demand as $q=0.5p^{-0.2}+0.5p^{-0.5}$
then given a $q=2$, there is no closed-form solution for the market-cleaing price, so we must use a numerical method for it.
Principle: Newton’s root-finding method: to solve $f(x)=0$, we can start with an initial $x(0)$, and set $x(k+1)=x(k)-f(x(k))/f’(x(k))$, until the difference is small enough.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
%matlab code:
%set the initial value of p
p=0.25;
%set a loop of 100 times
for i=1:100
%the movement of x by newton's method
deltap=(.5*p^-.2+.5*p^-.5-2)/(.1*p^-1.2+0.25*p^-1.5);
%generate a new p
p=p+deltap;
%test if the difference is small enough
if abs(deltap)<1.e-8, break, end
end
%get the value of p
disp(p);

question 2: the farmers decide their planting area a by expect a value of the price p. Now the goverment has a support plan, holding the price not less than 1. the outcome is donated as q, influnced by both a and weather y, where y is flexible. then we have
$a=0.5+0.5E[max(p,1)]$
$q=ay$
$p=3-2q$
solve them and we get that
$E[p]=3-2(0.5+0.5E[max(p,1)]$
due to the interaction of max and E operators, there is also no closed-form solution.
Principle: 1)fixed point iteration: to solve a=f(a), we can guess an initial a and keep updating it. 2)gaussian quadrature: we use single points to present the continious distribution of y, because it can not be computed directly. we use two vectors with probability w and realizations y.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
%matlab code:
%get ten points of the distribution of y
[y,w]=qnwnorm(10,1,0.1);
%set initial value of a
a=1;
%set a loop of 100 times
for it=1:100
%save the old a
aold=a;
%get ten secions of p at this situation
p=3-2*a*y;
%get the average value by observing ten sections
f=w'*max(p,1);
%generate a new a
a=0.5+0.5*f;
%test the difference
if abs(a-aold)<1.e-8, break, end
end

%get the values of planting area, supported expected price and non-sup expected price
disp(a);disp(f);disp(w'*p)

question 3: plot the function $f(x)=1-e^{2x}$ on the interval$ [-1,1] $using a grid of evenlyspaced points 0.01 units apart.

1
2
3
4
5
6
7
8
9
%matlab code:
%generate evenly-spaced x
x=linspace(-1,1,201);

%generate y as the question mentioned
y=1-exp(2*x);

%plot the figure of this function
plot(x,y)

qusetion 4: we have two 3*3 matrics A=[[0,-1,2][-2,-1,4][2,7,-3]] and B=[[-7,1,1][7,-3,-2][3,5,0]] and the vertical vector
$y=
[3;
-1;
2].$
1)formulate the standard matrix product C=A*B and solve the linear equation Cx=y. What are the values of C and x?

1
2
3
4
5
6
7
8
9
%matlab code:
A=[0 -1 2;-2 -1 4;2 7 -3];
B=[-7 1 1;7 -3 -2;3 5 0];
y=[3;-1;2];
Ca=A*B;
xa=inv(Ca)*y;
Cb=A.*B;
xb=inv(Cb)*y;
disp(xa);disp(Ca);disp(xb);disp(Cb)