Clear Filters
Clear Filters

Why I am i getting a negative value for the spread when i restricted it have positive values.?I would be glad if anyone could help.

1 view (last 30 days)
clear all
clc
IN=[-0.04844752 0.041968141 -0.044564664;
-0.304020248 0.131284505 0.472041681;
-0.074829705 -0.049999997 -0.094350919;
0.28895241 0.390694469 0.416666657;
-0.098011374 0.012270158 -0.067317739;
-0.175849974 -0.160909101 -0.174713209;
-0.141403094 -0.004999995 -0.098300003;
-0.210274339 -0.191784486 -0.109999985
]
OUT=[-0.148966655;
0.281067416;
-0.154999971;
0.360221535;
-0.120833755;
-0.18519102;
-0.136289001;
-0.184634596 ]
h=0.2
p=1-h
NEWIN=[ones(size(IN,1),1) IN]
num_NEWIN=size(NEWIN,2)
D=zeros(num_NEWIN,num_NEWIN)
E=(-1).*eye(num_NEWIN,num_NEWIN)
B=zeros(num_NEWIN,1)
A=[-NEWIN -p*abs(NEWIN); NEWIN -p*abs(NEWIN); D E]
b=[-OUT; OUT; B]
v1=sum(abs(NEWIN(:,1)))
v2=sum(abs(NEWIN(:,2)))
v3=sum(abs(NEWIN(:,3)))
v4=sum(abs(NEWIN(:,4)))
f=[zeros(num_NEWIN,1);v1;v2;v3;v4]
%f=[zeros(num_NEWIN,1);ones(num_NEWIN,1)]
x=linprog(f,A,b)
Center_coeff= x(1:4,1)
spread_coeff= x(5:8,1)

Accepted Answer

Constantino Carlos Reyes-Aldasoro
Just ran your code and had this:
spread_coeff =
0.0452
0
0
0
No negatives

More Answers (1)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!