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