<p>how do i plot these?
i have this utility function: <span class="math-container">$$U(x_1,x_2)=\log(x_1)+\beta \log(x_2)$$</span>
and this budget constraint: <span class="math-container">$$p_1 x_1+p_2 x_2=R$$</span>      where <span class="math-container">$R=3, p_1=0.5, p_2=0.5$</span>
i dont know how to plot these so i can show the optimum point from <span class="math-container">$MRS=p_1/p_2$</span></p>
<p>this is my code:</p>
<pre><code>clear all; clc; close all;
syms x1 x2 beta p1 p2 t x1_star x2_star

R=3; %disposable income
grid_points=100;
beta=1/3
p1=0.5;
p2=0.5;
t=0.25;
q_x1=p1+t %x1 quantity

maxX1=R/p1;
maxX2=R/p2;
maxX1_t=R/q_x1;


x1=linspace(0, maxX1, grid_points);
x2=(R-x1*p1)/p2; %budget constraint
plot(x1, x2, 'LineWidth',1);
hold on
x1_t=linspace(0, maxX1_t, grid_points);
x2_t=(R-x1_t*q_x1)/p2; %budget constraint
plot(x1_t, x2_t, 'LineWidth',1);


%optimal choices

syms x1 x2
%curve1

UU(x1,x2)=log(x1)+beta*log(x2);
SMS=diff(UU,x1)/diff(UU,x2)
% R=p1*x1+p2*x2
[x1_star,x2_star]=solve(p1*x1+p2*x2-R, (3*x2)/x1-p1/p2)

UU_1_star=UU(x1_star,x2_star)
UU_1_star=1.6392
X=solve(UU(x1,x2)==UU_1_star);
hold on
fplot(X)
ylim([0 6])
xlim([0 6])

%curve2

UU(x1,x2)=log(x1)+beta*log(x2);
[x1_star2,x2_star2]=solve(q_x1*x1+p2*x2-R, x2/(beta*x1)-q_x1/p2)
UU_2_star=UU(x1_star2,x2_star2)
UU_2_star=1.2338
X2=solve(UU(x1,x2)==UU_2_star);
fplot(X2)
</code></pre>
<p>As you can see i have problems plotting</p>

CC BY-SA 4.0
2020-11-17T01:19:02.020Z
I’m voting to close this question because it belongs to Stackoverflow.
Art
CC BY-SA 4.0
2020-11-17T05:55:30.660Z
It's economics related
develarist
CC BY-SA 4.0
2020-11-17T08:55:32.310Z
@Art I think this can stay according to our [help center](https://economics.stackexchange.com/help/on-topic): "Software questions: Questions related to software used in economics and econometrics, are on-topic here." This is clearly application of matlab to narrow economic problem
1muflon1
CC BY-SA 4.0
2020-11-18T00:23:55.000Z
Can you be more specific about what you want to plot on the graph? When I run your code, it seemed to produce [something](https://i.sstatic.net/WSYFx.png) that shows a tangency.
Herr K.
CC BY-SA 4.0
2020-11-18T00:56:41.193Z
the tangency point for the blue and yellow lines might be the marginal rate of substitution (MRS). He needs to say what he thinks is wrong about the graph
develarist
<preferences><matlab>
MATLAB code: Plot utility function and budget constraint
tonysnake92
# MATLAB code: Plot utility function and budget constraint

(Asked by: username_0 on 2020-11-15)

how do i plot these?
i have this utility function: $$U(x_1,x_2)=\log(x_1)+\beta \log(x_2)$$
and this budget constraint: $$p_1 x_1+p_2 x_2=R$$      where $R=3, p_1=0.5, p_2=0.5$
i dont know how to plot these so i can show the optimum point from $MRS=p_1/p_2$
this is my code:
clear all; clc; close all;
syms x1 x2 beta p1 p2 t x1_star x2_star

R=3; %disposable income
grid_points=100;
beta=1/3
p1=0.5;
p2=0.5;
t=0.25;
q_x1=p1+t %x1 quantity

maxX1=R/p1;
maxX2=R/p2;
maxX1_t=R/q_x1;


x1=linspace(0, maxX1, grid_points);
x2=(R-x1*p1)/p2; %budget constraint
plot(x1, x2, 'LineWidth',1);
hold on
x1_t=linspace(0, maxX1_t, grid_points);
x2_t=(R-x1_t*q_x1)/p2; %budget constraint
plot(x1_t, x2_t, 'LineWidth',1);


%optimal choices

syms x1 x2
%curve1

UU(x1,x2)=log(x1)+beta*log(x2);
SMS=diff(UU,x1)/diff(UU,x2)
% R=p1*x1+p2*x2
[x1_star,x2_star]=solve(p1*x1+p2*x2-R, (3*x2)/x1-p1/p2)

UU_1_star=UU(x1_star,x2_star)
UU_1_star=1.6392
X=solve(UU(x1,x2)==UU_1_star);
hold on
fplot(X)
ylim([0 6])
xlim([0 6])

%curve2

UU(x1,x2)=log(x1)+beta*log(x2);
[x1_star2,x2_star2]=solve(q_x1*x1+p2*x2-R, x2/(beta*x1)-q_x1/p2)
UU_2_star=UU(x1_star2,x2_star2)
UU_2_star=1.2338
X2=solve(UU(x1,x2)==UU_2_star);
fplot(X2)

As you can see i have problems plotting

**Tags:** preferences, matlab

> **Comments:**
> **username_1**: I’m voting to close this question because it belongs to Stackoverflow.  
> **username_2**: It's economics related  
> **username_3**: @username_1 I think this can stay according to our [help center](https://economics.stackexchange.com/help/on-topic): "Software questions: Questions related to software used in economics and econometrics, are on-topic here." This is clearly application of matlab to narrow economic problem  
> **username_4**: Can you be more specific about what you want to plot on the graph? When I run your code, it seemed to produce [something](https://i.sstatic.net/WSYFx.png) that shows a tangency.  
> **username_2**: the tangency point for the blue and yellow lines might be the marginal rate of substitution (MRS). He needs to say what he thinks is wrong about the graph  

---

## 0 answers

