MATLAB: How to show variation of two variables

3d graphicerror calculationnested loopresponse surface functiontank model

I am trying to run the following tank model, first with synthetic observation parameters, then with several sets of combinations of the two parameters (K and Smax). Those two pieces appear to work.
After that, I am trying to calculate the error (by comparing the synth values to all the model values) and then plot a mesh grid of the error as it varies with changes to each of the variables. The figure shows only Smax varying, while K appears to stay the same. This is incorrect.
Can anyone see why/show me how to fix this?
Code below, data attached.
Thank you!!
Spill Scenario Storage where k=0.1; Smax=50
SynthK=0.1;
SynthSmax=50;
Storage = [Precipmmday(1) 0];
Baseflow = [Precipmmday(1) 0];
for k1 = 2:length(Precipmmday)
Baseflow (k1,:) = [(Storage(k1-1,2)+Precipmmday(k1-1))*SynthK];
Storage(k1,:) = [(Storage(k1-1,2)+Precipmmday(k1-1))*(1-SynthK)];
end
SynthStorage = Storage;
SynthStorage (:,1) =[];
SynthSpill=SynthStorage - SynthSmax;
SynthSpill(SynthSpill<0)=0;
SynthStorage(SynthStorage>SynthSmax)=SynthSmax;
SynthBaseflow = Baseflow;
SynthBaseflow (:,1) = [];
SynthOutflow = SynthBaseflow + SynthSpill;
Run Model (10×10)
Baseflow = zeros(10,10);
Storage = zeros(10,10);
Storage = [Precipmmday(1) 0];
Baseflow = [Precipmmday(1) 0];
Smax = linspace(10,500,10);
K = linspace(0.01,1,10);
for k3 = 1:length(Smax)
for k2 = 1:length(K)
for k1 = 2:length(Precipmmday)
Baseflow(k1,k2,k3) = [(Storage(k1-1,2)+Precipmmday(k1-1))*K(k2)];
Storage(k1,k2,k3) = [(Storage(k1-1,2)+Precipmmday(k1-1))*(1-K(k2))];
end
ModelStorage = Storage;
ModelSpill=ModelStorage - Smax(k3);
ModelSpill(ModelSpill<0)=0;
ModelStorage(ModelStorage>Smax(k3))=Smax(k3);
ModelBaseflow = Baseflow;
ModelOutflow = ModelBaseflow + ModelSpill;
end
end
Calculate Difference
SynthOutflow = repmat(SynthOutflow,[1 10 10]);
Difference = ModelOutflow - SynthOutflow;
Root Mean Square Error
rmse = sqrt((sum((Difference(1:1087,:,:)).^2))/1087);
rmse1 = reshape(rmse,10,10);
RMSE Figure
figure;
mesh(K, Smax, rmse1);
xlabel('k')
ylabel('Smax')
zlabel('err')

Best Answer

Hello again!
I made some very slight changes in your ‘rmse’ and ‘rmse1’ calculations:
% Root Mean Square Error
rmse = sqrt(mean(Difference(1:1087,:,:).^2));
rmse1 = squeeze(rmse);
since ‘RMS’ is the root of the mean of the square (or so I was taught). If you then plot your data (you will also need to rotate it in the figure window; view([-5 15]) shows it as clearly as possible), you see that there is a very slight change in ‘err’ at the minimum of ‘Smax’ as ‘K’ goes from 0 to 0.1, but no changes with respect to ‘K’ anywhere else, at least that I can see.
So your plot is showing the changes in ‘err’ with respect to ‘K’. It’s simply difficult to see them because they’re so small.