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)

 Akzeptierte Antwort

John D'Errico
John D'Errico am 22 Aug. 2021
Bearbeitet: John D'Errico am 22 Aug. 2021

0 Stimmen

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 Kommentar

cierra
cierra am 22 Aug. 2021
Yes. Thank you so much for the quick reply!!! :):):)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

am 22 Aug. 2021

Kommentiert:

am 22 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by