Plot with varying variable in optimization

Hello,
I need to find the change of one endogeneous variable in the optimization given a change of one exogenous variable and make a plot.
I got the scope of exogenous variable. how to plot it? I meet the error for the coding below
clear; close all; clc;
w=2;
y=10
q=0.5:1.5 % here q is the varing variable and it ranges from 0.5 to 1.5
X0=[1,1,.1];
[K,L,lambda]=q2_f(q,w,y,X0) %here are the solution of the optimization
figure
plot(q,K)

 채택된 답변

John D'Errico
John D'Errico 2021년 8월 22일
편집: John D'Errico 2021년 8월 22일

0 개 추천

You want to vary q, and for every value of q, get a corresponding value for K?
w=2;
y=10
q=0.5:1.5 % here q is the varing variable and it ranges from 0.5 to 1.5
X0=[1,1,.1];
% preallocate with NaNs, so if a nan remains, it is clear what you did wrong
K = nan(size(q));
for ind = 1:numel(q)
[K(ind),L,lambda]=q2_f(q(ind),w,y,X0) %here are the solution of the optimization
end
figure
plot(q,K)
I could have used zeros to preallocate too, but I often prefer to use NaNs.

댓글 수: 1

cierra
cierra 2021년 8월 22일
Yes. Thank you so much for the quick reply!!! :):):)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

질문:

2021년 8월 22일

댓글:

2021년 8월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by