Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
big problem, need some help

Subject: big problem, need some help

From: Greg

Date: 20 Nov, 2010 21:49:04

Message: 1 of 8

hey guys, i have data points that i was given in class and when i graph it, it seems to be a polynomial function with powers less than one. my job is to create an equation for this graph. I thought i could do some curve fitting to find the equation but polyfit only works with integer order values. now since i know this function has powers that are less than 1, is there another function i could use that acts like polyfit that takes in orders less than one? the reason i repost this is because some jokester sent me a link to an irrelavant site trying to be funny

Subject: big problem, need some help

From: Richard Startz

Date: 20 Nov, 2010 22:57:34

Message: 2 of 8

On Sat, 20 Nov 2010 21:49:04 +0000 (UTC), "Greg "
<gharrington44@gmail.com> wrote:

>hey guys, i have data points that i was given in class and when i graph it, it seems to be a polynomial function with powers less than one. my job is to create an equation for this graph. I thought i could do some curve fitting to find the equation but polyfit only works with integer order values. now since i know this function has powers that are less than 1, is there another function i could use that acts like polyfit that takes in orders less than one? the reason i repost this is because some jokester sent me a link to an irrelavant site trying to be funny

Try taking logs of both sides and then doing a linear fit on the logs.

Subject: big problem, need some help

From: Matt Fig

Date: 20 Nov, 2010 23:31:03

Message: 3 of 8

Richard Startz <richardstartz@comcast.net> wrote in message
> Try taking logs of both sides and then doing a linear fit on the logs.

I believe this will only work if there is only one term. Something like this, I presume:

x = 1:.1:20;
y = 5*x.^.771; % See if we can find this using POLYFIT.
p = polyfit(log(x),log(y),1);
yp = exp(p(2)).*x.^p(1); % Use our polynomial to construct a new y.
plot(x,y,'-b',x(1:5:end),yp(1:5:end),'*r') % Compare original with derived.

If, however, we have something like:

y = 5*x.^.771 + 3*x.^.233 + 600;

then other methods will have to be used because taking the logarithm of both sides yields.

log(y) = log(5*x.^.771 + 3*x.^.233 + 600)

and the logarithm on the RHS doesn't distribute linearly over the terms.

Subject: big problem, need some help

From: Richard Startz

Date: 20 Nov, 2010 23:55:00

Message: 4 of 8

On Sat, 20 Nov 2010 23:31:03 +0000 (UTC), "Matt Fig"
<spamanon@yahoo.com> wrote:

>Richard Startz <richardstartz@comcast.net> wrote in message
>> Try taking logs of both sides and then doing a linear fit on the logs.
>
>I believe this will only work if there is only one term. Something like this, I presume:
>
>x = 1:.1:20;
>y = 5*x.^.771; % See if we can find this using POLYFIT.
>p = polyfit(log(x),log(y),1);
>yp = exp(p(2)).*x.^p(1); % Use our polynomial to construct a new y.
>plot(x,y,'-b',x(1:5:end),yp(1:5:end),'*r') % Compare original with derived.
>
>If, however, we have something like:
>
>y = 5*x.^.771 + 3*x.^.233 + 600;
>
>then other methods will have to be used because taking the logarithm of both sides yields.
>
>log(y) = log(5*x.^.771 + 3*x.^.233 + 600)
>
>and the logarithm on the RHS doesn't distribute linearly over the terms.

Quite true. If you have the statistics toolbox, look at nlinfit.

Subject: big problem, need some help

From: Greg

Date: 21 Nov, 2010 01:17:03

Message: 5 of 8

ok guys here is what i have. i looked at the data and it seems to look like a y = Cx^p where C is a constant and p < 1. By hand calculations, i found the derivative to look something like a y' = Cx^p graph where C is still a constant and p is less than 0. I then took natural log of both sides to get ln(y') = ln(C) + pln(x). When i plot ln(y') vs ln(x) i will be able to solve for my y intercept and slope, thus allowing me to solve for C and P. But when i try to fit that to the data, it has huge error which means there is another function involved with more coefficients. That's why I was wondering if there was a function in matlab that could fit a curve to my nonlinear function with powers less than one and give me the coefficients. I then could write a function that would minimize the error to it.

Subject: big problem, need some help

From: Greg

Date: 21 Nov, 2010 01:24:04

Message: 6 of 8

My data also contains a data point at (0,0). When I try to take log(0), it is going to be undefined so that is not going to work....

Subject: big problem, need some help

From: Greg

Date: 21 Nov, 2010 01:26:03

Message: 7 of 8

My data has a point at (0,0) so taking log of each of those values will be undefined. So won't this not work?

Subject: big problem, need some help

From: Greg Heath

Date: 22 Nov, 2010 06:41:58

Message: 8 of 8

On Nov 20, 8:17 pm, "Greg " <gharringto...@gmail.com> wrote:
> ok guys here is what i have. i looked at the data and it seems to look like a y = Cx^p where C is a constant and p < 1. By hand calculations, i found the derivative to look something like a y' = Cx^p graph where C is still a constant and p is less than 0. I then took natural log of both sides to get ln(y') = ln(C) + pln(x). When i plot ln(y') vs ln(x) i will be able to solve for my y intercept and >slope, thus allowing me to solve for C and P.

Why not do this for y instead of y'?
Then the first model is y1 = C*x^p, C > 0, 0<p<1
Next plot y-y1 and, excluding (0,0), y/y1
to see if the correction yielding y2 should
be additive or multiplicative.

Hope this helps.

Greg

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us