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:
linear regression on log log plots

Subject: linear regression on log log plots

From: Alireza Y.

Date: 2 Dec, 2009 09:00:17

Message: 1 of 5

Hello,
I have two variables (vectors):
L=[0 200 400 600 800 1000] %L:Length
S=[0.002 0.001 0.003 0.001 0.002 0.01] %S:Slope
and I have to calculate the coefficients Lambda(slope) and Gama(intercept) of a straight line by regression of my data on log-log graph.
formula: lnS=Gama-Lambda*lnL;
In cftool, axes are normal (not log-log). I also tried ployfit(x,y,n) in polyfit(log(L),log(S),1) way, but it didn't work and answer was NaN NaN.
what code should i use for fitting a straight line(linear fitting) and calculation of Lambda and Gama.
thaks in advance

Subject: linear regression on log log plots

From: Frederic Moisy

Date: 2 Dec, 2009 10:40:19

Message: 2 of 5

It does not work because L(1) = 0, so log(L(1)) = -Inf,
and polyfit can't fit a line with an Inf point.
Try: polyfit(log(L(2:end)),log(S(2:end)),1) and it will work.
F





"Alireza Y." <bilgi_yk2@yahoo.com> wrote in message <hf5ab1$qs8$1@fred.mathworks.com>...
> Hello,
> I have two variables (vectors):
> L=[0 200 400 600 800 1000] %L:Length
> S=[0.002 0.001 0.003 0.001 0.002 0.01] %S:Slope
> and I have to calculate the coefficients Lambda(slope) and Gama(intercept) of a straight line by regression of my data on log-log graph.
> formula: lnS=Gama-Lambda*lnL;
> In cftool, axes are normal (not log-log). I also tried ployfit(x,y,n) in polyfit(log(L),log(S),1) way, but it didn't work and answer was NaN NaN.
> what code should i use for fitting a straight line(linear fitting) and calculation of Lambda and Gama.
> thaks in advance

Subject: linear regression on log log plots

From: Richard Startz

Date: 2 Dec, 2009 14:52:13

Message: 3 of 5

On Wed, 2 Dec 2009 09:00:17 +0000 (UTC), "Alireza Y."
<bilgi_yk2@yahoo.com> wrote:

>Hello,
>I have two variables (vectors):
>L=[0 200 400 600 800 1000] %L:Length
>S=[0.002 0.001 0.003 0.001 0.002 0.01] %S:Slope
>and I have to calculate the coefficients Lambda(slope) and Gama(intercept) of a straight line by regression of my data on log-log graph.
>formula: lnS=Gama-Lambda*lnL;
>In cftool, axes are normal (not log-log). I also tried ployfit(x,y,n) in polyfit(log(L),log(S),1) way, but it didn't work and answer was NaN NaN.
>what code should i use for fitting a straight line(linear fitting) and calculation of Lambda and Gama.
>thaks in advance

Try
[ones(length(L,1) log(L)]\log(S)

-Dick Startz

Subject: linear regression on log log plots

From: Alireza Y.

Date: 4 Dec, 2009 06:27:07

Message: 4 of 5

Thank you so much for your help.

"Frederic Moisy" <moisy@fast.u-psud.fr> wrote in message <hf5g6j$ghk$1@fred.mathworks.com>...
> It does not work because L(1) = 0, so log(L(1)) = -Inf,
> and polyfit can't fit a line with an Inf point.
> Try: polyfit(log(L(2:end)),log(S(2:end)),1) and it will work.
> F
>
>
>
>
>
> "Alireza Y." <bilgi_yk2@yahoo.com> wrote in message <hf5ab1$qs8$1@fred.mathworks.com>...
> > Hello,
> > I have two variables (vectors):
> > L=[0 200 400 600 800 1000] %L:Length
> > S=[0.002 0.001 0.003 0.001 0.002 0.01] %S:Slope
> > and I have to calculate the coefficients Lambda(slope) and Gama(intercept) of a straight line by regression of my data on log-log graph.
> > formula: lnS=Gama-Lambda*lnL;
> > In cftool, axes are normal (not log-log). I also tried ployfit(x,y,n) in polyfit(log(L),log(S),1) way, but it didn't work and answer was NaN NaN.
> > what code should i use for fitting a straight line(linear fitting) and calculation of Lambda and Gama.
> > thaks in advance

Subject: linear regression on log log plots

From: Alireza Y.

Date: 4 Dec, 2009 06:30:28

Message: 5 of 5

Thank you so much for your help.

Richard Startz <richardstartz@comcast.net> wrote in message <invch5luil6hpr3t7erhbgq1mg7tkgc1qf@4ax.com>...
> On Wed, 2 Dec 2009 09:00:17 +0000 (UTC), "Alireza Y."
> <bilgi_yk2@yahoo.com> wrote:
>
> >Hello,
> >I have two variables (vectors):
> >L=[0 200 400 600 800 1000] %L:Length
> >S=[0.002 0.001 0.003 0.001 0.002 0.01] %S:Slope
> >and I have to calculate the coefficients Lambda(slope) and Gama(intercept) of a straight line by regression of my data on log-log graph.
> >formula: lnS=Gama-Lambda*lnL;
> >In cftool, axes are normal (not log-log). I also tried ployfit(x,y,n) in polyfit(log(L),log(S),1) way, but it didn't work and answer was NaN NaN.
> >what code should i use for fitting a straight line(linear fitting) and calculation of Lambda and Gama.
> >thaks in advance
>
> Try
> [ones(length(L,1) log(L)]\log(S)
>
> -Dick Startz

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