Plot with varying variable in optimization
1 view (last 30 days)
Show older comments
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)
0 Comments
Accepted Answer
John D'Errico
on 22 Aug 2021
Edited: John D'Errico
on 22 Aug 2021
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.
More Answers (0)
See Also
Categories
Find more on Multiobjective Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!