finding relation between two variables, being discharge and water level in a river

26 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2024-10-30,11:28
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'})
mdl =
Nonlinear regression model: y ~ F(c,h) Estimated Coefficients: Estimate SE tStat pValue ________ _______ ______ __________ c 0.55426 0.07972 6.9525 3.8816e-10 Number of observations: 100, Error degrees of freedom: 99 Root Mean Squared Error: 0.376 R-Squared: -0.656, Adjusted R-Squared -0.656 F-statistic vs. zero model: 173, p-value = 1.77e-23
c_est = mdl.Coefficients.Estimate
c_est = 0.5543
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')
.

更多回答(1 个)

Aquatris
Aquatris 2024-10-30,12:33
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
Local minimum possible. fminunc stopped because it cannot decrease the objective function along the current search direction.
fprintf('C_real was: %.2f, Estimated C is: %.4f',c_real,c_fit)
C_real was: 3.30, Estimated C is: 3.2855
% 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')

类别

Help CenterFile Exchange 中查找有关 Log Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by