help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Polynom, 2. degree


From: Ivan Sutoris
Subject: Re: Polynom, 2. degree
Date: Mon, 16 Feb 2009 13:36:42 +0100

On Mon, Feb 16, 2009 at 1:07 PM, Peter Stalder
<address@hidden> wrote:
> Dear list,
>
> I just started with Octave and I'd like to check a result compard to R and 
> excel. The script I'm using in R is:
>
> # Input
> n <- 7;
> y <- c(0.00,0.17,0.41,1.52,2.83,4.27,7.24);
> x <- c(0,17,35,71,107,143,215);
> # Polynom 2. degree
> polyfit2 <- lm(y~poly(x,2));
> # Graphic
> plot(y~x,pch=18);
> lines(sort(x), polyfit2$fit[order(x)],col='red', lwd=2);
> # Summary
> summary(polyfit2);
>
> How do I write a polynom (2. degree) in Octave? On the end, I need the 
> intercept and slope.
>
> Thank you.
> Peter

You can use "polyfit" function to fit coeficients and "polyval" to
evaluate polynomial at given point:

  y = [0.00,0.17,0.41,1.52,2.83,4.27,7.24];
  x = [0,17,35,71,107,143,215];
  fit = polyfit(x,y,2);
  plX = 0:1:215;
  plY = polyval(fit,plX);
  plot(x,y,'ro', plX,plY,'b-');

Regards
Ivan Sutoris


reply via email to

[Prev in Thread] Current Thread [Next in Thread]