finding relation between two variables, being discharge and water level in a river
Mostrar comentarios más antiguos
I have to variables, being a water level (h) and a discharge (q).
The relation is to be of the form q = h^c
How do I solve this, find the relation betwen the discharge and water level
Hope one of you can give me advice
regards
Johannes
Respuesta aceptada
Más respuestas (1)
Here is another way using unconstarint optimization:
% define some parameters
c_real = 3.2965;% actual c value in q = h^c
h_min = 20; % min h for data creation
h_max = 100; % max h for data creation
N = 1e3; % number of data points
% create data
h = sort(h_min + (h_max-h_min) .* rand(N,1)); % sorted random numbers between 20 and 100
myModel = @(x) h.^x; % model structure
q = myModel(c_real).*(1+randn(N,1)*.1); % noisy measurement data using c_real value
% optimization cost function (can be in many other forms)
myFun = @(x) max(abs(q-myModel(x)));
x0 = 1; % initial guess for c
c_fit = fminunc(myFun,x0); % solve the optimization
fprintf('C_real was: %.2f, Estimated C is: %.4f',c_real,c_fit)
% plots
plot(h,myModel(c_real),'k--',h,q,'b.',h,myModel(c_fit),'r-','LineWidth',3)
xlabel('h')
ylabel('q')
legend('Real Model','Noisy Data','Fit')
Categorías
Más información sobre Surrogate Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

