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)

 采纳的回答

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.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by