finding relation between two variables, being discharge and water level in a river
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Johannes Deelstra
el 30 de Oct. de 2024
Respondida: Aquatris
el 30 de Oct. de 2024
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
0 comentarios
Respuesta aceptada
Star Strider
el 30 de Oct. de 2024
Your question is a bit ambiguous.
If you have data of some sort and you want to fit that model to it in order to deteermine ‘c’ there are several functions that will solve it.
h = sort(rand(100,1));
q = rand(100,1);
objfcn = @(c,h) h.^c; % Anonymous Function
mdl = fitnlm(h, q, objfcn, rand, CoefficientNames={'c'})
c_est = mdl.Coefficients.Estimate
hv = linspace(min(h), max(h), 10*numel(h)).';
qv = objfcn(c_est,hv);
figure
plot(h, q, '.', 'DisplayName','Data')
hold on
plot(hv, qv, '-r', 'DisplayName','Fitted Model')
hold off
xlabel('h')
ylabel('q')
title(sprintf('q = h^{%.3f}',c_est))
legend('Location','best')
.
0 comentarios
Más respuestas (1)
Aquatris
el 30 de Oct. de 2024
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')
0 comentarios
Ver también
Categorías
Más información sobre Log Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!