Hello, Quadratic and power curve fitting

조회 수: 2 (최근 30일)
Charitha Heshan
Charitha Heshan 2018년 3월 18일
댓글: Charitha Heshan 2018년 3월 18일
pressure=[10 15 25 40 50 55];
flow=[94 116 147 183 215 220];
a = -0.0170 ; b = 3.8870 ; c = 59.0062 ;
p = 5 : 60 ;
f = 5 : 300 ;
f_par = a* p.^ 2 +b * p + c
alpha = 72.0144 ; beta = 2.7842 ;
f_exp = alpha * p.^beta;
plot (pressure,flow,'o',p,f_par,p,f_exp,'--')
legend ('eperimental data','parabolic fit','exponential fit')
xlabel ('pressure psi') , ylabel ('flow gpm'),grid
Could some one correct my code where Y axis (f = flow rate) would stop plotting at value 400. currently it plots to 7*10^6.
thank you very much

답변 (1개)

John D'Errico
John D'Errico 2018년 3월 18일
편집: John D'Errico 2018년 3월 18일
What do you expect? As you generated it, we see:
f_exp
f_exp =
Columns 1 through 13
6360.5 10567 16231 23540 32675 43815 57130 72791 90962 1.1181e+05 1.3549e+05 1.6215e+05 1.9197e+05
Columns 14 through 26
2.2509e+05 2.6165e+05 3.0182e+05 3.4573e+05 3.9354e+05 4.4539e+05 5.0142e+05 5.6178e+05 6.266e+05 6.9602e+05 7.7019e+05 8.4923e+05 9.333e+05
Columns 27 through 39
1.0225e+06 1.117e+06 1.2169e+06 1.3224e+06 1.4336e+06 1.5505e+06 1.6734e+06 1.8024e+06 1.9376e+06 2.0791e+06 2.2271e+06 2.3816e+06 2.5429e+06
Columns 40 through 52
2.7109e+06 2.886e+06 3.0681e+06 3.2574e+06 3.4541e+06 3.6582e+06 3.8698e+06 4.0892e+06 4.3163e+06 4.5514e+06 4.7946e+06 5.0459e+06 5.3055e+06
Columns 53 through 56
5.5735e+06 5.85e+06 6.1352e+06 6.4291e+06
The problem is NOT the plot. The problem is that somehow, you generated a garbage model.
ALWAYS look at what you got from a computation. Plotting garbage and expecting to magically see what you want to see is a good path to failure.
And since we have not been shown where those coefficients came from, how can we realistically help you?
Perhaps you wanted to do this:
mdl = fittype('power1')
mdl =
General model Power1:
mdl(a,b,x) = a*x^b
fittedmdl = fit(pressure',flow',mdl)
fittedmdl =
General model Power1:
fittedmdl(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 29.17 (23.95, 34.4)
b = 0.5049 (0.456, 0.5538)
f_exp = fittedmdl.a*p.^fittedmdl.b;
plot (pressure,flow,'o',p,f_par,p,f_exp,'--')
legend ('eperimental data','parabolic fit','exponential fit')
xlabel ('pressure psi') , ylabel ('flow gpm'),grid
That presumes the Curve fitting TB.
  댓글 수: 1
Charitha Heshan
Charitha Heshan 2018년 3월 18일
Thank you for your response ,
if true
% code
function [a2,a1,a0] = QuadraticRegression (x,y)
x=[10 15 25 40 50 55]; y=[94 116 147 183 215 220];
n = length (x) sx = sum(x) sy = sum(y) sx2 = sum(x.^2) sx3 = sum(x.^3) sx4 = sum(x.^4) sxy = sum(x.*y) sx2y= sum(x.*x.*y)
A = [ n sx sx2; sx sx2 sx3;sx2 sx3 sx4] b = [sy;sxy;sx2y]
w= A\b
a2 = w(3) a1 = w(2) a0 = w(1)
end
This is the model i used to find the coefficients a0 a1 a3 .
if true
% code
function [a1 , a0] = linearRegression (x,y)
x=[10 15 25 40 50 55]; y=[94 116 147 183 215 220];
n=length(x) sx= sum(x) sy= sum(y) sxx= sum(x.*x) sxy= sum(x.*y) den = n*sxx - sx^2 a1 = (n*sxy - sx*sy) /den a0 = (sxx*sy - sxy*sx) /den
l = zeros (n,1) for i = 1:n, l(i) = a1*x(i) + a0; plot (x,y,'o') hold on plot (x,l) end
end
the above model was used to obtain a linear equation y= n0x+n1 and converted it to a power function as follows = alpha = 72.0144 ; beta = 2.7842 ;
function = alpha * p.^beta;
so i'm suppose to plot both quadratic and power functions on the same graph .
the original plot model was provided to me by the professor, i honestly lack knowledge to come up with by my self.
thank you for your time

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by