How to plot an antenna pattern in a polar diagram in Octave? - plot

I'm having some problems with polar plot in Octave. In particular I made a script that combine the horizontal and vertical antenna pattern in order to obtain the 3D antenna pattern of the antenna such that the result is a matrix of 360x360 elements. If I plot the matrix by means of surf function I obtain that image but I would like to get an antenna pattern diagram. How I can do that?
EDIT:
theta3D = linspace(0, 2*pi - (2*pi/360), 360);
phi3D = linspace(0, 2*pi - (2*pi/360), 360);
%% from dBm to dB
maxGainVdB = mGVNnA - 30;
maxGainHdB = mGHNnA - 30;
%% from dB to Watt
maxGainVWatt = 10.^(maxGainVdB/10);
maxGainHWatt = 10.^(maxGainHdB/10);
%% normalization
maxGainVWattNorm = maxGainVWatt./max(maxGainVWatt);
maxGainHWattNorm = maxGainHWatt./max(maxGainHWatt);
%% Gv and Gh
Gv = 10*log10(maxGainVWattNorm);
Gh = 10*log10(maxGainHWattNorm);
%% weighting factors
% where "i" is theta and j is phi
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
w1(i, j) = maxGainVWattNorm(i)*(1 - maxGainHWattNorm(j));
w2(i, j) = maxGainVWattNorm(j)*(1 - maxGainHWattNorm(i));
end
end
%% normalization-related parameter
k = 2; %% As indicated in Chapter 2
%% estimated G
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
estG(i, j) = ((Gh(i)*w1(i,j) + Gv(j)*w2(i,j))/((w1(i,j)^k + w2(i,j)^k))^(1/k));
end
end
figure
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG)
DATA
mGHNnA = [0.0762 0.0976 0.1207 0.146 0.1744 0.2066 0.2428 0.2827 0.3256 0.3705 0.4165 0.4631 0.5107 0.5602 0.6129 0.6704 0.7334 0.8021 0.8754 0.9518 1.0294 1.1067 1.1834 1.2608 1.3419 1.4318 1.5376 1.6653 1.8213 2.011 2.2382 2.5046 2.8096 3.1494 3.5171 3.8976 4.2687 4.6021 4.8717 5.0727 5.201 5.2687 5.2965 5.3066 5.3189 5.3365 5.3865 5.4558 5.5635 5.7028 5.8633 6.0489 6.2538 6.4708 6.6929 6.914 7.1293 7.3344 7.5209 7.6879 7.8455 7.9974 8.1362 8.2677 8.4072 8.547 8.6955 8.8539 9.025 9.21 9.4099 9.6251 9.8558 10.102 10.362 10.636 10.924 11.224 11.536 11.858 12.189 12.528 12.875 13.229 13.59 13.954 14.323 14.696 15.071 15.447 16.203 16.58 17.089 17.593 18.093 18.588 19.077 19.56 20.036 20.506 20.969 21.424 21.861 22.278 22.683 23.081 23.47 23.856 24.235 24.609 24.98 25.344 25.698 26.037 26.347 26.622 26.87 27.09 27.289 27.459 27.601 27.729 27.849 27.962 28.068 28.158 28.244 28.282 28.272 28.233 28.204 28.181 28.182 28.2 28.21 28.203 28.206 28.181 28.185 28.238 28.346 28.526 28.794 29.158 29.616 30.155 30.753 31.375 31.988 32.556 33.032 33.32 33.435 33.452 33.476 33.597 33.831 34.167 34.581 35.047 35.48 35.784 36.026 36.134 35.959 35.742 35.544 35.466 35.575 35.746 35.995 36.162 36.19 36.11 35.912 35.695 35.529 35.417 35.401 35.464 35.467 35.622 35.747 35.773 35.787 35.827 35.802 35.722 35.596 35.544 35.59 35.687 35.784 35.857 35.867 35.804 35.679 35.462 35.131 34.68 34.179 33.68 33.231 32.833 32.532 32.326 32.18 32.035 31.752 31.265 30.628 29.95 29.221 28.526 27.919 27.419 27.03 26.737 26.542 26.415 26.341 26.301 26.269 26.241 26.212 26.179 26.143 26.102 26.051 25.983 25.892 25.795 25.707 25.636 25.584 25.542 25.502 25.464 25.424 25.362 25.269 25.156 25.013 24.827 24.604 24.343 24.042 23.713 23.361 22.998 22.62 22.229 21.827 21.418 21.004 20.587 20.156 19.72 19.278 18.833 18.385 17.934 17.478 17.018 16.555 16.086 15.614 15.138 14.658 14.175 13.689 13.336 12.982 12.629 12.277 11.926 11.577 11.23 10.887 10.549 10.215 9.8873 9.5665 9.2535 8.9474 8.6508 8.3601 8.0783 7.8076 7.5485 7.2995 7.0654 6.8356 6.6223 6.418 6.2237 6.0401 5.8621 5.6946 5.5356 5.384 5.2382 5.0961 4.9558 4.8113 4.6579 4.5018 4.3427 4.182 4.022 3.8609 3.7051 3.5585 3.4213 3.2873 3.1583 3.032 2.9015 2.7555 2.6037 2.4462 2.284 2.1188 1.9533 1.7903 1.6325 1.4827 1.3435 1.209 1.0844 0.9762 0.8832 0.7952 0.7224 0.6616 0.609 0.5607 0.5128 0.4625 0.4103 0.3567 0.3033 0.2521 0.2051 0.164 0.1295 0.1013 0.0786 0.06 0.0442 0.0304 0.0182 0.0083 0.0019 0 0.0035 0.0125 0.0242 0.0388 0.0564]
and
mGVNnA = [ 1.7 1.1099 0.7069 0.4755 0.2901 0.1465 0.0475 0 0.0014 0.0449 0.1292 0.2868 0.4673 0.7364 1.2223 1.9732 3.0173 4.3603 5.9631 7.7179 9.5019 9.832 8.9113 8.2694 8.0057 8.1343 8.6399 9.5171 10.742 12.285 14.065 16.092 18.473 21.416 25.15 27.353 27.395 26.174 23.967 21.86 20.131 18.734 17.599 16.638 15.887 15.369 15.082 15.024 15.211 15.606 16.196 16.958 17.868 18.867 20 20.151 19.842 19.695 19.725 19.787 19.905 20.082 20.265 20.432 20.595 20.789 21.013 21.281 21.623 22.058 22.536 23.101 23.715 24.38 25.113 25.898 26.737 27.595 28.478 29.381 30.284 31.155 31.971 32.721 33.389 33.969 34.473 34.88 35.237 35.563 35.885 36.251 36.805 37.442 38.143 38.785 39.282 39.452 39.252 38.808 38.293 37.764 37.253 36.773 36.34 35.953 35.634 35.368 35.192 35.093 35.087 35.161 35.305 35.638 35.968 36.19 36.22 36.098 35.797 35.382 35.001 34.788 34.768 34.921 35.411 36.172 36.807 36.485 36.261 35.984 35.618 35.165 34.735 34.498 34.647 35.242 36.268 37.584 38.828 39.695 40.087 40.283 40.635 41.382 42.64 43.356 41.606 40.07 39.359 39.185 39.081 38.836 38.624 38.456 38.255 38.206 38.493 39.266 40.491 41.983 43.328 42.563 40.545 38.503 37.071 36.429 36.194 36.104 35.836 35.579 35.481 35.506 35.707 35.994 36.07 36.031 36.033 36.214 36.667 37.435 38.147 38.873 39.727 40.902 42.706 43.934 43.635 43.926 44.379 44.797 45.114 45.558 46.371 47.239 49.24 52.957 57.002 55.602 53.712 53.855 57.666 52.999 48.404 45.794 44.523 44.54 44.979 45.826 47.281 48.725 49.537 49.035 47.911 45.782 43.136 40.9 39.415 38.682 38.471 38.664 39.083 39.55 39.89 39.954 39.921 40.111 40.907 41.583 41.361 41.264 40.952 40.156 39.005 37.776 36.579 35.531 34.625 33.843 33.158 32.54 32.059 31.661 31.352 31.117 30.908 30.74 30.578 30.447 30.306 30.141 29.997 29.704 29.318 28.964 28.61 28.262 27.903 27.512 27.083 26.622 26.123 25.592 25.037 24.464 23.88 23.292 22.702 22.114 21.537 20.976 20.433 19.985 19.564 19.172 18.811 18.484 18.191 17.938 17.728 17.566 17.458 17.411 17.431 17.437 16.937 16.486 16.093 15.757 15.479 15.269 15.133 15.062 15.072 15.144 15.254 15.407 15.568 15.726 15.86 15.971 16.077 16.2 16.408 16.719 17.174 17.79 18.611 19.673 21.051 22.834 24.971 27.442 29.851 27.032 24.994 23.406 21.624 20.012 18.602 17.435 16.433 15.668 15.115 14.729 14.47 14.339 14.383 14.654 15.252 16.216 14.91 13.992 13.353 12.978 12.89 13.16 13.841 14.942 16.463 18.341 20.559 23.437 26.905 27.021 23.385 19.308 16.1 13.668 11.801 10.36 9.2831 8.5509 8.1662 8.1298 8.4381 7.8963 6.1559 4.6964 3.4785 2.4834 ]

I have no idea which kind of polar plots you are expecting, but the below code may help you to make it as an example.
2D polar plot
% polar plot for G vs. phi, when theta = pi
polar(phi3D, estG(:,length(theta3D)/2+1));
hold on;
% polar plot for G vs. theta, when phi = pi
polar(theta3D, estG(length(phi3D)/2+1,:));
legend("G vs. phi #(theta=pi)","G vs. theta #(phi=pi)");
title("2D radiation pattern");
hold off;
- 3D polar plot
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG,'LineStyle','none');
xlabel("theta");
ylabel("phi");
zlabel("G");
colormap("jet");
colorbar

The code that you have included does generate an estimate of gain vs theta and phi, however, you are plotting it on rectangular coordinates. if you noticed, in the resultant figure, the x and y axes are ranging from 0 to 2pi.
you created a (theta, phi, magnitude) data set, and need to convert that to an x,y,z data set.
doing a coordinate transformation, similar to:
xconv = estG.*sin(theta3D).*cos(phi3D);
yconv = estG.*sin(theta3D).*sin(phi3D);
zconv = estG.*cos(theta3D);
may give you what you need.
surf(xconv,yconv,zconv,'Edgecolor','none')
produces:
Since I'm not exactly sure what output would be correct from this data, I can't tell if that quite has it. There may be some ordering issues with mesh and surf plot data that i'm not aware of.
I recommend always starting simple. Work with a unit gain omnidirectional antenna, and see if your process above can go from two circle plots to a sphere. then generate more complex patterns.
for reference, here's a decent set of classroom exercises on 3D parametric plots

Related

Calculation of Akaike Information Criterion

My data file is given below.
Expt. (Col 1:2) Fit1 (Col 3:4) Fit2 (Col 5:6)
x_expt. y_expt x_fit y_fit x_fit y_fit
2.89394 3.04606 2.95515 3.14485 2.96485 3.16485
2.90727 3.22788 2.96788 3.31939 2.97758 3.34061
2.92788 3.42545 2.98242 3.50303 2.99212 3.52606
2.97576 3.62303 2.99818 3.69758 3.00788 3.72182
2.97394 3.84182 3.01576 3.90182 3.02545 3.92848
3.00061 4.06364 3.03515 4.11818 3.04485 4.14606
3.02788 4.29939 3.05636 4.34545 3.06606 4.37515
3.05758 4.54848 3.08 4.58545 3.0897 4.61697
3.09455 4.80424 3.10606 4.83818 3.11576 4.87212
3.12909 5.07818 3.13515 5.10424 3.14485 5.14061
3.1697 5.37152 3.16667 5.38485 3.17758 5.42364
3.20727 5.65333 3.20182 5.68061 3.21273 5.72182
3.25394 5.98 3.24061 5.99152 3.25212 6.03576
3.30061 6.30909 3.28364 6.32121 3.29576 6.36364
3.35697 6.66061 3.33091 6.66667 3.34364 6.71515
3.41212 7.0303 3.38242 7.02424 3.39636 7.07879
3.47273 7.41818 3.44 7.40606 3.45455 7.46667
3.54606 7.82424 3.50303 7.81212 3.51818 7.87273
3.62242 8.24848 3.57212 8.2303 3.58909 8.29697
3.69939 8.69697 3.64788 8.67879 3.66667 8.74545
3.79212 9.16364 3.73152 9.14545 3.75212 9.21212
3.8903 9.66061 3.82364 9.6303 3.84545 9.70909
4.00242 10.1818 3.92424 10.1455 3.94848 10.2242
4.13212 10.6909 4.03455 10.6849 4.06121 10.7697
4.29697 11.2667 4.15576 11.2546 4.18485 11.3394
4.39273 11.8909 4.28788 11.8485 4.32061 11.9394
4.5503 12.5091 4.43273 12.4727 4.46848 12.5636
4.72061 13.2 4.59152 13.1212 4.63091 13.2242
4.89152 13.8424 4.76424 13.8061 4.80788 13.9091
5.07818 14.5636 4.95333 14.5212 5.00061 14.6303
5.30303 15.3212 5.15879 15.2667 5.21091 15.3818
5.54606 16.0788 5.38303 16.0485 5.44 16.1636
5.79212 16.8909 5.62667 16.8667 5.68848 16.9879
6.07273 17.7273 5.89212 17.7212 5.95939 17.8424
6.35152 18.6303 6.18182 18.6121 6.25455 18.7333
6.67879 19.5394 6.49091 19.5394 6.5697 19.6667
6.99394 20.4727 6.8303 20.503 6.91515 20.6364
7.42424 21.4485 7.19394 21.5091 7.28485 21.6424
7.73939 22.497 7.59394 22.5515 7.69091 22.6909
8.17576 23.5879 8.01818 23.6424 8.12121 23.7758
8.64242 24.7091 8.47879 24.7697 8.58788 24.903
9.12727 25.8242 8.97576 25.9394 9.09091 26.0788
9.59394 27.0727 9.50909 27.1515 9.6303 27.2909
10.1636 28.297 10.0788 28.4061 10.2061 28.5455
10.6909 29.5212 10.6909 29.7091 10.8242 29.8424
11.3939 31.0121 11.3455 31.0485 11.4909 31.1818
12.1152 32.4121 12.0485 32.4364 12.1939 32.5697
12.903 33.8667 12.8 33.8667 12.9455 34
13.6364 35.3515 13.5939 35.3455 13.7515 35.4667
14.4303 36.8546 14.4485 36.8606 14.6 36.9818
15.2849 38.5515 15.3515 38.4242 15.503 38.5394
16.2606 40.1939 16.3091 40.0303 16.4606 40.1455
17.2364 41.8909 17.3212 41.6788 17.4788 41.7879
18.3212 43.7091 18.3939 43.3697 18.5455 43.4727
19.4667 45.5576 19.5273 45.103 19.6788 45.2061
20.5152 46.8849 20.7212 46.8788 20.8667 46.9758
22.0606 49.1758 21.9818 48.6909 22.1152 48.7939
23.3152 51.1879 23.303 50.5515 23.4303 50.6485
24.7212 53.1576 24.6909 52.4485 24.8061 52.5455
26.2121 55.4727 26.1455 54.3879 26.2485 54.4849
a). Col 1:2 represent experimental data.
b). Col 3:4 is fitted data using non-linear least squares fitting using 4 adjustable parameters.
c). Col 5:6 is fitted data using non-linear least squares fitting using 5 adjustable parameters with one parameter fixed to 0.
I wish to calculate AIC for both the fits and conclude which fit is better. Can anybody suggest how to solve this problem in R or Excel?

Plotting a 1D dot plot in SAS

Hello, I would like to plot something that is close to this but
I cannot seem to get it.
I have the data
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
And I tried
proc freq data=table2_1;
tables Modified_Mortar / plots=freqplot (type=dotplot);
tables Unmodifided_Mortar / plots=freqplot (type=dotplot);
run;
but it gave me an unnecessarily huge plot which was spaced equally and cannot compare the two distributions as I intended.
I played around a bit with sgplot and this is the closest I could come up with. It's not exact, but with a little fiddling in an image editor you can pretty much get it.
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
retain mod_line 0.75 unmod_line 0;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sgplot data=table2_1;
label Modified_Mortar = 'Strength (kgf/cm squared)';
scatter x = Modified_Mortar y=mod_line / markerattrs=(symbol=circlefilled color=black size=10);
scatter x = Unmodifided_Mortar y=unmod_line / markerattrs=(symbol=circlefilled color=bib size=10);
refline -0.25 / axis=y lineattrs=(color=bib thickness=2) name='mod' legendlabel='Unmodified' ;
refline 0.5 / axis=y lineattrs=(color=black thickness=2) name='unmod' legendlabel='Modified';
yaxis display=(nolabel) min=-0.25 max=15;
xaxis values=(16.24 to 17.50 by 0.14) min=16.30 max=17.40 valueattrs=(size=12) labelattrs=(size=12);
keylegend 'mod' 'unmod' / location=outside position=bottom valueattrs=(size=12);
run;
Here is a different approach that uses the data in a treatment:response categorical form. A labeled triangle marker is used to show the mean (triangle apex being the balance point)
data have;
treatment = 'Modified '; y=1.13; input response #; output;
treatment = 'Unmodified'; y=0.13; input response; output;
attrib
response label = "Strength (kgf/cm2)"
;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sql;
create table plot as
select * from have
outer union corresponding
select
treatment,
case treatment
when ('Unmodified') then -0.15
when ('Modified ') then 0.85
else 0
end as y2,
mean(response) as mean format=5.2
from have
group by treatment;
quit;
ods proclabel "Concrete dot plot";
ods graphics / height=220px width=800px;
proc sgplot data=plot description="Response to treatment";
title "Concrete strength response to treatment";
scatter
x=response y=y
/ markerattrs=(symbol=circlefilled color=black size=12px)
;
scatter
x=mean y=y2
/ datalabel=mean
datalabelpos=bottom
markerattrs=(symbol=triangle color=black size=12px)
;
keylegend
/ exclude = ("y" "y2")
;
yaxis
offsetmin = 0.2
values = ( 0 1 2 )
valuesdisplay = ( "Unmodified" "Modified" " " )
display = ( noticks nolabel )
colorbands = odd
;
xaxis
grid
;
refline 0.00 ;
refline 1.00 ;
run;
title;
footnote;

Unexpected error using Jump with Julia

I am trying to solve an optimization problem, I am getting error as
"ERROR: Expected m to be a JuMP model, but it has type Int64
in validmodel(::Int64, ::Symbol) at C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:247
in macro expansion; at C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:252 [inlined]
in macro expansion; at .\REPL[608]:3 [inlined]
in anonymous at .\:?"
Please see the following code(error in constraint 2). Please don't mind the way I have defined arrays, any help is appreciated. Thank you
using JuMP
using Gurobi
m = Model(solver = GurobiSolver()) #if GurobiSolver is to be used .
## insert all matrixs here
#this is the cost for plant to warehouse
plant=4 #last index for {1,2,3}
product=5 #ast index for {2,3,4}
customer=50
warehouse=4
#variable(m, x[i=1:product ,k=1:plant,l=1:warehouse]>=0) #plant to warehouse
#variable(m, y[i=1:product ,k=1:warehouse,l=1:customer]>=0) #warehouse to customer
#variable(m, z[i=1:product ,k=1:plant,l=1:customer ]>=0) #plant to customer
#variable(m, p[i=1:product ,k=1:plant]>=0) #any product i produced at plant k
#THIS GIVES COST OF PRODUCING AT ANY PRODUCT I AT PLANT K
PC=[500 500 500 500;
400 400 400 400;
300 300 300 300;
200 200 200 200;
100 100 100 100]
#DEMAND OF I AT ANY COSTOMER M, SHOULD BE A MATRIX OF (5*50)
D=[4650.28 10882.70 7920.68 2099.06 4920.32 5077.80 2259.10 9289.30 9782.28 4671.85 6625.68 6956.80 5288.12 4144.78 11121.56 9152.47 10206.88 4601.63 2718.91 1439.39 2984.38 3631.17 3934.48 12314.28 4188.04 8437.43 6302.34 1248.62 6286.56 7333.46 11027.86 6233.33 7240.82 5652.13 10276.03 1197.22 11160.13 4510.31 8850.49 8291.09 1081.47 7652.23 3936.85 2640.47 7726.72 1422.96 1644.78 1060.39 6858.66 6554.45;
528.11 4183.80 352.45 366.34 1961.78 3419.11 337.44 708.15 3556.56 1649.95 583.25 1525.97 1569.92 349.93 1904.59 2221.80 2139.63 1822.87 546.11 784.93 948.33 1424.26 1910.64 2275.11 1527.57 2477.49 1592.14 90.86 2635.48 131.02 2402.35 2669.67 105.34 1350.60 4233.60 411.54 687.88 89.09 213.23 2817.29 8.08 1586.51 577.07 1529.34 2919.06 393.97 85.45 214.93 3193.94 1565.64;
480.26 622.67 131.04 14.45 1299.71 599.27 83.08 197.37 1986.77 409.08 371.12 1249.92 216.21 62.43 34.96 1752.75 227.06 184.26 219.92 577.37 138.71 36.23 1659.02 1323.50 236.64 2557.64 76.74 74.08 363.64 52.96 456.67 1589.86 81.89 617.11 509.86 145.52 14.13 83.22 215.03 2749.34 7.12 490.00 120.42 456.03 430.22 165.02 66.16 150.70 2806.58 1403.70;
307.36 474.39 7.56 11.76 882.03 222.62 27.29 158.13 55.94 332.98 171.36 492.81 44.12 24.08 15.57 739.97 11.09 199.51 136.46 194.40 63.72 2.42 355.99 1005.42 66.33 1647.51 47.22 21.32 218.06 11.54 305.81 387.71 8.50 248.38 9.20 76.05 13.12 39.83 146.52 379.44 2.75 239.53 94.06 136.96 290.16 237.75 9.04 110.64 842.58 395.08;
76.52 280.62 5.06 6.75 281.41 215.58 5.78 54.69 20.79 22.08 78.50 322.13 34.13 6.37 11.66 178.33 3.40 142.11 60.70 46.17 6.96 1.15 227.70 669.39 3.21 526.85 45.91 17.00 131.43 11.19 189.00 43.93 3.36 110.66 1.75 41.34 0 38.63 50.78 241.19 0 176.32 94.25 99.59 153.50 123.02 3.76 122.52 853.48 99.62]
a = Array{Float64}(5,4,4)
a[1,1,1]=a[2,1,1]=a[3,1,1]=a[4,1,1]=a[5,1,1]=0.2*528.42
a[1,2,1]=a[2,2,1]=a[3,2,1]=a[4,2,1]=a[5,2,1]=0.2*1366.16
a[1,3,1]=a[2,3,1]=a[3,3,1]=a[4,3,1]=a[5,3,1]=0.2*1525.41
a[1,4,1]=a[2,4,1]=a[3,4,1]=a[4,4,1]=a[5,4,1]=0.2*878.11
a[1,1,2]=a[2,1,2]=a[3,1,2]=a[4,1,2]=a[5,1,2]=0.2*1692.25
a[1,2,2]=a[2,2,2]=a[3,2,2]=a[4,2,2]=a[5,2,2]=0.2*1553.06
a[1,3,2]=a[2,3,2]=a[3,3,2]=a[4,3,2]=a[5,3,2]=0.2*817.18
a[1,4,2]=a[2,4,2]=a[3,4,2]=a[4,4,2]=a[5,4,2]=0.2*2164.69
a[1,1,3]=a[2,1,3]=a[3,1,3]=a[4,1,3]=a[5,1,3]=0.2*2006.5
a[1,2,3]=a[2,2,3]=a[3,2,3]=a[4,2,3]=a[5,2,3]=0.2*1385.04
a[1,3,3]=a[2,3,3]=a[3,3,3]=a[4,3,3]=a[5,3,3]=0.2*998.58
a[1,4,3]=a[2,4,3]=a[3,4,3]=a[4,4,3]=a[5,4,3]=0.2*2148.45
a[1,1,4]=a[2,1,4]=a[3,1,4]=a[4,1,4]=a[5,1,4]=0.2*1073.07
a[1,2,4]=a[2,2,4]=a[3,2,4]=a[4,2,4]=a[5,2,4]=0.2*368.35
a[1,3,4]=a[2,3,4]=a[3,3,4]=a[4,3,4]=a[5,3,4]=0.2*450.12
a[1,4,4]=a[2,4,4]=a[3,4,4]=a[4,4,4]=a[5,4,4]=0.2*1129.27
#objective(m, Min ,sum(a[i,k,l]* x[i,k,l] for i=1:product for k=1:plant for l=1:warehouse) + sum(c_dash[i,l,m]* y[i,l,m] for i=1:product for l=1:warehouse for m=1:plant) +sum(c_dash_dash[i,k,m]* z[i,k,m] for i=1:product for k=1:plant for m=1:customer)+sum(PC[i,k]* p[i,k] for i=1:product for k=1:plant)) #to be changes
#constraint(m,p[1,2]==0)
#constraint(m,p[1,3]==0)
#constraint(m,p[1,4]==0)
#constraint(m,p[2,1]==0)
#constraint(m,p[2,3]==0)
#constraint(m,p[2,4]==0)
#constraint(m,p[3,1]==0)
#constraint(m,p[3,2]==0)
#constraint(m,p[3,4]==0)
#constraint(m,p[4,1]==0)
#constraint(m,p[4,2]==0)
#constraint(m,p[4,3]==0)
#constraint(m,p[5,1]==0)
#constraint(m,p[5,2]==0)
#constraint(m,p[5,3]==0)
#constraint(m,p[1,1]<=450000)
#constraint(m,p[2,2]<=108000)
#constraint(m,p[3,3]<=45000)
#constraint(m,p[4,4]<=18000)
#constraint(m,p[5,4]<=9000)
#constraint 1
#constraint(m,415728.69-0.8* sum(y[i,l,m] for i=1:product for l=1:warehouse for m=1:customer) <=0)
#constrainst 2
for m=1:customer
for i=1:product
#constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 ) #cant get
end
end
#constrainst 2
for m=1:customer
for i=1:product
#constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 ) #cant get
end
end
The error explains the problem very well. Your outer-loop variable here is m, which makes usage of m inside the loop refers to the loop variable and not to your model. m is also used to hold the model in the outer-scope. Change your loop variable or model variable to something else and the problem is fixed.

Suggestion for curve fitting

I have this set of data:
X: Y:
0. 0.
0.001417162 0.0118
0.002352761 0.0128
0.003123252 0.0135
0.003866221 0.0138
0.004045083 0.0147
0.005544762 0.0151
0.006260197 0.0156
0.007195755 0.0157
0.007883656 0.0158
0.008805432 0.0159
0.009314465 0.0165
0.010566391 0.0168
0.011047891 0.0186
0.011666955 0.0177
0.012341036 0.0225
0.013193938 0.0399
0.013854235 0.087
0.014500764 0.1479
0.015381122 0.198
0.015601208 0.2586
0.01638525 0.3111
0.016976706 0.3693
0.017691939 0.42
0.018338382 0.4737
0.018861027 0.5223
0.01963122 0.5691
0.021625353 0.6183
0.020923988 0.6684
0.021377815 0.711
0.021927895 0.7551
0.022574222 0.7938
0.023633053 0.8382
0.023646804 0.8742
0.024279325 0.912
0.025131822 0.9495
0.0256543 0.9891
0.026094271 1.0215
0.026685464 1.0596
0.027345378 1.098
0.028101497 1.1328
0.028513912 1.1739
0.029077528 1.1997
0.029723601 1.2339
0.030355902 1.2741
0.031056901 1.3041
0.031428005 1.3383
0.032087723 1.3665
0.032692438 1.3983
0.033242157 1.4262
0.033846824 1.4589
0.034410239 1.4877
0.035248448 1.5222
0.035729364 1.5534
0.036430096 1.5861
0.037034618 1.6179
0.037694064 1.6536
0.038408425 1.6842
0.039067798 1.7121
0.039521096 1.7427
0.040207877 1.7763
0.04071607 1.8075
0.041279177 1.8381
0.04129291 1.8711
0.042707418 1.9065
0.043366544 1.9332
0.043860863 1.9659
0.044368889 1.9959
0.045055371 2.0202
0.045700624 2.0487
0.04626347 2.0796
0.047059639 2.1105
0.047540055 2.1339
0.048308673 2.1618
0.048857648 2.1849
0.049557546 2.2203
0.050229948 2.2425
0.052082233 2.2716
0.051355084 2.2983
0.051945039 2.3193
0.052466363 2.3475
0.053371748 2.3718
0.053851839 2.3937
0.054647359 2.4189
0.055072521 2.4372
0.055675941 2.4633
0.056306742 2.4882
0.057060898 2.5131
0.057691594 2.5332
0.058582712 2.5527
0.059007671 2.5755
0.059597094 2.5941
0.060172767 2.6115
0.065187502 2.6403
0.06131028 2.6592
0.061968042 2.6808
0.062598344 2.6991
0.063173791 2.7246
0.063790292 2.7441
0.064393043 2.7633
0.065091624 2.7795
0.065502522 2.8011
0.066433804 2.8212
0.066598135 2.8368
0.067351271 2.8545
0.067981104 2.8665
0.068610879 2.8845
0.069309041 2.9046
0.069870256 2.9214
0.070253498 2.9355
0.070828319 2.9499
0.07159467 2.9691
0.072046228 2.9856
0.072620893 2.9982
0.07326391 3.0108
0.073893183 3.0255
0.074467682 3.0387
0.075165218 3.0531
0.075862676 3.0654
0.076395973 3.0735
0.077230012 3.0879
0.077571798 3.0996
0.077968246 3.1116
0.078720058 3.1251
0.079485442 3.1332
0.080168736 3.1473
0.080797297 3.1524
0.081671703 3.1647
0.082518656 3.1761
0.082737205 3.1794
0.083242565 3.1911
0.083843476 3.207
0.084594523 3.2157
0.083993693 3.2217
0.086028058 3.2313
0.086806105 3.2412
0.087515804 3.2475
0.087979788 3.2562
0.089221428 3.2658
0.089289641 3.2727
0.090053572 3.2823
0.090599168 3.285
0.091485638 3.2988
0.092508299 3.3006
0.092794607 3.309
0.093585278 3.3177
0.094443969 3.3255
0.095029975 3.336
0.095752165 3.3381
0.096378886 3.3468
0.097182604 3.3498
0.097781901 3.3573
0.098585385 3.3612
0.099238967 3.3702
0.102192566 3.372
0.100464189 3.3816
0.101226388 3.3879
0.101961246 3.396
0.102519116 3.4038
0.103335387 3.4113
0.103920292 3.4134
0.104777107 3.4206
0.105416212 3.423
0.105932869 3.4308
0.106952407 3.4353
0.107550426 3.4431
0.108284246 3.4479
0.108759804 3.4539
0.109439081 3.4587
0.110118251 3.4662
0.11096027 3.4701
0.111802122 3.4749
0.112182257 3.4857
0.113132445 3.4902
0.113878868 3.4929
0.114530181 3.5028
0.11465229 3.5076
0.116063069 3.513
0.116619106 3.5181
0.117378448 3.5247
0.118246089 3.5295
0.118869589 3.5286
0.119479439 3.5364
0.120292424 3.5451
0.120807227 3.5511
0.121728283 3.5565
0.122283519 3.5625
0.123068837 3.5622
0.123745705 3.5691
0.124544254 3.5775
0.125247919 3.5796
0.125924395 3.5868
0.126614273 3.5892
0.128683133 3.5958
0.127993643 3.5991
0.128602023 3.6057
0.129507645 3.6093
0.130115772 3.6132
0.130669753 3.6156
0.131682911 3.6222
0.132263658 3.6234
0.132911821 3.6288
0.133870342 3.6291
0.136717348 3.6336
0.13504451 3.6396
0.135692157 3.6372
0.13621828 3.6432
0.137068001 3.6465
0.141030546 3.6522
0.138470251 3.6501
0.139009423 3.6567
0.140181824 3.6615
0.140532116 3.6633
0.141124835 3.6588
0.141717448 3.6675
0.14257924 3.6711
0.143319661 3.6741
0.143844585 3.6729
0.144813453 3.6753
0.145243967 3.678
0.1472209 3.6849
0.14672342 3.6879
0.147301565 3.6888
0.147866163 3.6933
0.148403782 3.6927
0.149277216 3.6972
0.149962355 3.7011
0.151922897 3.7077
0.151426165 3.7023
0.152070559 3.7089
0.153251595 3.7107
0.153587034 3.7134
0.15429804 3.7191
0.154861361 3.7191
0.155706144 3.7221
0.157086785 3.7206
0.157086785 3.7272
0.156925966 3.7269
0.158480178 3.7335
0.15912306 3.7272
0.159618519 3.7356
0.160381629 3.7359
0.161171304 3.7386
0.161853731 3.7377
0.162415608 3.7398
0.163151233 3.7437
0.163993625 3.7443
0.165062969 3.7533
0.165330242 3.7509
0.166065112 3.7512
0.166866568 3.7569
0.167494215 3.7635
0.168108371 3.7569
0.168829162 3.7638
0.169536423 3.7626
0.173429745 3.7581
0.171070418 3.7617
0.171803762 3.7653
0.172790131 3.7635
0.172936723 3.7644
0.174029244 3.7695
0.174761783 3.7701
0.175334355 3.7668
0.176173017 3.7704
0.176705362 3.7722
0.177490375 3.7701
0.178261854 3.774
0.178979922 3.7797
0.178793775 3.78
0.180774223 3.7887
0.182394664 3.8301
0.18451827 3.8169
0.186282158 3.8067
0.186772642 3.7731
0.188058046 3.7782
0.188587916 3.7734
0.189395747 3.7749
0.189885613 3.7707
0.190560674 3.7734
0.191447234 3.7752
0.192280569 3.7713
0.193007849 3.7704
0.193946376 3.7701
0.194329613 3.7734
0.195188367 3.7647
0.195716677 3.7644
0.196416507 3.7683
0.197142527 3.7695
0.197709986 3.7596
0.198923623 3.7662
0.199714786 3.7617
0.200189355 3.7626
0.2011382 3.7683
0.201915434 3.7665
0.202310538 3.7599
0.203258508 3.7656
0.204153451 3.7569
0.204903352 3.753
0.205311089 3.7512
0.206192075 3.753
0.207033292 3.7461
0.207966146 3.7539
0.208478393 3.7473
0.209318747 3.7425
0.210119413 3.7455
0.21077548 3.7443
0.21140512 3.7425
0.21234924 3.7443
0.213122589 3.7461
0.213751552 3.7443
0.214498207 3.7422
0.215192234 3.7425
0.216030006 3.7395
0.216762788 3.7437
0.217508397 3.7377
0.218096851 3.7446
0.223098604 3.7383
0.219547672 3.7386
0.220187807 3.7395
0.220906094 3.7386
0.221872127 3.7368
0.222381072 3.7404
0.223111647 3.7374
0.223789808 3.7365
0.224207027 3.7278
0.225288796 3.7359
0.225862032 3.7326
0.226487197 3.7368
0.226396039 3.7302
0.227775995 3.7308
0.228426593 3.7287
0.229115997 3.7278
0.229063975 3.7269
0.230312139 3.726
0.23101389 3.7104
plot(x,y)
Can you please give me suggestions of models (I've tried polynomials and I either get a bad fit or a overfit). Thanks!
Just monkeying around in Python/Numpy for a few minutes, it looks like you want a formula like
Yfit(x) = Ymax * (1 - exp(-(x-x0)/a) )
x0 is where the data starts to take off from zero. Looks like x0 = 0.012 give or take a little. Ymax is the maximum value. The parameter a sets how fast the curve rises, and it look like you want a = 0.007 or so.
Polynomials are bad for any data that levels off and holds steady before or after the interesting parts. Polynomials like to wiggle, like a snake trying to go through lined-up croquet wickets. Even fitting loosely with least-squares or whatever, polynomials don't like flatness. But the shape sure looks like a constant minus a decaying exponential - very common in electronics and physics.
The initial zero values, I take to be meaningless and not needing fitting. The Yfit values you get could be clipped to zero when negative, for plotting and comparison.
If exp(-(x-x0)/a) doesn't work well enough, you could try other functions that quickly fade to zero, such as 1/(1+x^p) for some power p>=2, or use a Gaussian exp(-(x-x0)^2 / a^2)
I actually see a slight curve - the Y values go up to max, and then slightly back down. Maybe add a quadratic term to your model, like:
Y_extra_term(x) = ((x-xmax)/b)^2
where xmax is the x value where y is maximum.
(BTW, I'm no expert on R, so use the correct syntax not whatever I write.)

r lattice wireframe different colours under specific conditions

I plot data in a 3D form using wireframe from the lattice package to show the volatility term structure. Here is the data:
library(lattice)
con <- textConnection (" X1M X2M X3M X6M X9M X12M X18M X24M VSTOXX Euro.Stoxx.50
2006-04-14 14.850 15.076 15.462 15.950 16.396 16.700 17.146 17.968 15.068 3793.830
2006-04-21 16.468 15.028 15.476 15.900 16.342 16.858 17.402 18.030 14.930 3824.030
2006-04-28 14.576 15.070 14.560 15.552 15.996 16.262 16.850 17.630 14.810 3865.136
2006-05-05 14.806 14.990 14.770 15.584 16.132 16.378 16.868 17.668 14.906 3848.302
2006-05-12 15.944 14.968 14.734 15.260 15.840 15.582 16.496 17.338 15.028 3844.066
2006-05-19 27.708 18.316 17.466 17.250 17.412 17.478 17.796 17.646 19.204 3655.658
2006-05-26 23.756 20.862 19.650 19.922 19.348 19.256 19.362 19.330 22.732 3613.942
2006-06-02 23.172 21.504 20.720 21.046 20.332 20.188 20.054 20.404 22.078 3638.574
2006-06-09 24.972 22.898 22.366 22.416 21.448 21.204 20.788 21.146 23.168 3535.830
2006-06-16 28.138 24.660 23.888 23.330 22.604 22.010 21.850 22.248 25.150 3451.960
2006-06-23 21.114 20.606 20.256 19.898 19.820 19.954 20.350 21.168 21.194 3525.386
2006-06-30 20.722 20.188 19.884 19.566 19.360 19.438 19.808 20.088 20.508 3555.864
2006-07-07 18.348 18.380 18.574 18.702 18.552 19.038 19.374 19.806 18.370 3653.206
2006-07-14 21.944 19.834 19.922 19.660 19.606 19.740 20.096 20.332 19.960 3597.120
2006-07-21 24.876 21.276 21.160 20.654 20.536 20.746 21.008 21.330 21.224 3544.618
2006-07-28 18.506 18.696 18.642 19.106 19.332 19.806 20.248 20.644 18.606 3659.466
2006-08-04 18.718 18.934 18.914 19.282 19.292 19.714 20.080 20.470 18.878 3682.964
2006-08-11 20.586 19.798 19.534 19.666 19.504 19.736 20.154 20.570 19.878 3676.808
2006-08-18 19.258 17.696 18.112 18.452 18.628 19.080 19.698 20.068 17.566 3773.618
")
Dat<- read.table(con, header = TRUE)
I would like to show two following things in a 3D plot (separately) :
1.) I can simply control levels for which I have different colours by
data2<-Dat[,c(8,7,6,5,4,3,2,1)]
wireframe(as.matrix(data2),
aspect = c(61/87, 0.4), drape = TRUE,
scales = list(arrows = F, cex= 0.5, font = 1),
xlab='Date', ylab='Maturity', zlab='Value',
col.regions=c("#FF3030","#551A8B","#43CD80"),
at=c(0,18,25,30))
but how can I have different colours for the periods whith flat/steep/inverse term structure ?
2.) The data set actually represents 9 weeks before and after the 2006-06-16 (or any other date,not necessarilly 9 weeks time span ) and I would like to highlight this specific date either by different colour in a 3D plot or some arrow / text/...
Thanks,
Alexander

Resources