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 ExchangeNonlinear 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