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
0 个评论
采纳的回答
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'})
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 个评论
更多回答(1 个)
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
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Log Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!