Polynomial fit from the equation

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

Maybe you see the problem?
Ayup...in
plot(time, log10(y4), 'g-')
you transformed the output of the transformed model input again in the same direction instead of reverse back to original space...
plot(time, y4.^10, 'g-')
instead but I'd suggest recasting somewhat and use
yHat=10.^polyval(x);
when you compute the predicted values rather than waiting.

More Answers (1)

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

Tags

Asked:

on 10 Jan 2018

Commented:

on 10 Jan 2018

Community Treasure Hunt

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

Start Hunting!