Polynomial fit from the equation
Show older comments
Hello guys, I have an equation y=a+b*lg(x),
Time values x=[ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
Data values y=[39.06 41.72 43.43 47.87 49.2 52.39 56.32 64.29 69.49 70.18 75.42 79.42 95.79 102.45 110.04 119.89 125.99 130.88 151.13 157.01 174.57]
And I am trying to draw a line with the given values, using the equation above and using polyfit polyval functions. But I don't get any output line. My code is:
z = log10(data)
p = polyfit(time, z, 1)
y4 = polyval(p, time)
figure
plot(time, log10(y4), 'g-')
Maybe you see the problem? Thanks in advance
Accepted Answer
More Answers (1)
James Tursa
on 10 Jan 2018
You appear to have both x and time meaning the same thing, and y and data meaning the same thing. Maybe it is just a variable naming issue. E.g., try
z = log10(y);
p = polyfit(x, z, 1);
y4 = polyval(p, x);
figure
plot(x, log10(y4), 'g-');
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!