solving equation system

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

solving equation system

Brigitte Diekhaus
hello,

it`s my first time using octave and I want to solve the following equation
system:

29.3 = A*124.5^4+B*124.5^3+C*124.5^2+124.5*D+F,
126.7 = A*111^4+B*111^3+C*111^2+D*111+F,
236.4 = A*88.9^4+B*88.9^3+C*88.9^2+D*88.9+F,
284.7 = A*75.5^4+B*75.5^3+C*75.5^2+D*75.5+F,
315.5 = A*63^4+B*63^3+C*63^2+D*63+F },

I need to find the variables {A,B,C,D,F}

to get a function like this:

y(x)=a*x^4+b*x^3+c*x^2+d*x+e

I Don`t know the syntax I have to use with octave to solve this equation
system.

many thanks in advance.

Brigitte



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: solving equation system

M Singh
Looks simple. Define a coefficient matrix and solve it :

octave:6>
a=[1,124.5,124.5^2,124.5^3,124.5^4;1,111,111^2,111^3,111^4;1,88.9,88.9^2,88.9^3,88.9^4;1,75.5,75.5^2,75.5^3,75.5^4;1,63,63^2,63^3,63^4]
a =

   1.0000e+00   1.2450e+02   1.5500e+04   1.9298e+06   2.4026e+08
   1.0000e+00   1.1100e+02   1.2321e+04   1.3676e+06   1.5181e+08
   1.0000e+00   8.8900e+01   7.9032e+03   7.0260e+05   6.2461e+07
   1.0000e+00   7.5500e+01   5.7002e+03   4.3037e+05   3.2493e+07
   1.0000e+00   6.3000e+01   3.9690e+03   2.5005e+05   1.5753e+07

octave:7> f=[29.3,126.7,236.4,284.7,315.5]'
f =

   29.300
  126.700
  236.400
  284.700
  315.500

octave:8> a\f
ans =

   -2.6907e+02
    2.9366e+01
   -5.0372e-01
    3.5786e-03
   -1.0222e-05

I hope that someone can point out a shorter way to define the coefficient
matrix since all its rows are of the form [1,x,x^2,x^3,x^4].

HTH

On Tuesday 19 April 2005 12:15, Brigitte Diekhaus wrote:

> hello,
>
> it`s my first time using octave and I want to solve the following equation
> system:
>
> 29.3 = A*124.5^4+B*124.5^3+C*124.5^2+124.5*D+F,
> 126.7 = A*111^4+B*111^3+C*111^2+D*111+F,
> 236.4 = A*88.9^4+B*88.9^3+C*88.9^2+D*88.9+F,
> 284.7 = A*75.5^4+B*75.5^3+C*75.5^2+D*75.5+F,
> 315.5 = A*63^4+B*63^3+C*63^2+D*63+F },
>
> I need to find the variables {A,B,C,D,F}
>
> to get a function like this:
>
> y(x)=a*x^4+b*x^3+c*x^2+d*x+e
>
> I Don`t know the syntax I have to use with octave to solve this equation
> system.
>
> many thanks in advance.
>
> Brigitte
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: solving equation system

Dmitri A. Sergatskov
Madhusudan Singh wrote:

> I hope that someone can point out a shorter way to define the coefficient
> matrix since all its rows are of the form [1,x,x^2,x^3,x^4].
>

help vander

> HTH
>

Regards,

Dmitri.
--



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

RE: solving equation system

HALL, BENJAMIN            PW
In reply to this post by Brigitte Diekhaus
It looks like you're trying to fit a 4th-order polynomial to the data

xx = [124.5; 111;    88.9;  75.5;  63  ];
yy = [ 29.3; 126.7; 236.4; 284.7; 315.5];

which you can do using polyfit

coeffs = polyfit( xx, yy, 4 )

coeffs =

   -1.0222e-05
    3.5786e-03
   -5.0372e-01
    2.9366e+01
   -2.6907e+02



-----Original Message-----
From: Madhusudan Singh [mailto:[hidden email]]
Sent: Tuesday, April 19, 2005 1:52 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: solving equation system


Looks simple. Define a coefficient matrix and solve it :

octave:6>
a=[1,124.5,124.5^2,124.5^3,124.5^4;1,111,111^2,111^3,111^4;1,88.9,88.9^2,88.
9^3,88.9^4;1,75.5,75.5^2,75.5^3,75.5^4;1,63,63^2,63^3,63^4]
a =

   1.0000e+00   1.2450e+02   1.5500e+04   1.9298e+06   2.4026e+08
   1.0000e+00   1.1100e+02   1.2321e+04   1.3676e+06   1.5181e+08
   1.0000e+00   8.8900e+01   7.9032e+03   7.0260e+05   6.2461e+07
   1.0000e+00   7.5500e+01   5.7002e+03   4.3037e+05   3.2493e+07
   1.0000e+00   6.3000e+01   3.9690e+03   2.5005e+05   1.5753e+07

octave:7> f=[29.3,126.7,236.4,284.7,315.5]'
f =

   29.300
  126.700
  236.400
  284.700
  315.500

octave:8> a\f
ans =

   -2.6907e+02
    2.9366e+01
   -5.0372e-01
    3.5786e-03
   -1.0222e-05

I hope that someone can point out a shorter way to define the coefficient
matrix since all its rows are of the form [1,x,x^2,x^3,x^4].

HTH

On Tuesday 19 April 2005 12:15, Brigitte Diekhaus wrote:

> hello,
>
> it`s my first time using octave and I want to solve the following equation
> system:
>
> 29.3 = A*124.5^4+B*124.5^3+C*124.5^2+124.5*D+F,
> 126.7 = A*111^4+B*111^3+C*111^2+D*111+F,
> 236.4 = A*88.9^4+B*88.9^3+C*88.9^2+D*88.9+F,
> 284.7 = A*75.5^4+B*75.5^3+C*75.5^2+D*75.5+F,
> 315.5 = A*63^4+B*63^3+C*63^2+D*63+F },
>
> I need to find the variables {A,B,C,D,F}
>
> to get a function like this:
>
> y(x)=a*x^4+b*x^3+c*x^2+d*x+e
>
> I Don`t know the syntax I have to use with octave to solve this equation
> system.
>
> many thanks in advance.
>
> Brigitte
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: solving equation system

Eric Chassande-Mottin-5
In reply to this post by M Singh

> I hope that someone can point out a shorter way to define the coefficient
> matrix since all its rows are of the form [1,x,x^2,x^3,x^4].

here, a is a vandermonde matrix

a=vander([124.5 111 88.9 75.5 63]);

octave:1> a=vander([124.5 111 88.9 75.5 63])
a =

   2.4026e+08   1.9298e+06   1.5500e+04   1.2450e+02   1.0000e+00
   1.5181e+08   1.3676e+06   1.2321e+04   1.1100e+02   1.0000e+00
   6.2461e+07   7.0260e+05   7.9032e+03   8.8900e+01   1.0000e+00
   3.2493e+07   4.3037e+05   5.7002e+03   7.5500e+01   1.0000e+00
   1.5753e+07   2.5005e+05   3.9690e+03   6.3000e+01   1.0000e+00

you need to flip it to choose the same coordinate system as you did:

a=fliplr(a);

> octave:6>
> a=[1,124.5,124.5^2,124.5^3,124.5^4;1,111,111^2,111^3,111^4;1,88.9,88.9^2,88.9^3,88.9^4;1,75.5,75.5^2,75.5^3,75.5^4;1,63,63^2,63^3,63^4]
> a =
>
>    1.0000e+00   1.2450e+02   1.5500e+04   1.9298e+06   2.4026e+08
>    1.0000e+00   1.1100e+02   1.2321e+04   1.3676e+06   1.5181e+08
>    1.0000e+00   8.8900e+01   7.9032e+03   7.0260e+05   6.2461e+07
>    1.0000e+00   7.5500e+01   5.7002e+03   4.3037e+05   3.2493e+07
>    1.0000e+00   6.3000e+01   3.9690e+03   2.5005e+05   1.5753e+07

eric.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: solving equation system

Przemek Klosowski
In reply to this post by M Singh
   I hope that someone can point out a shorter way to define the coefficient
   matrix since all its rows are of the form [1,x,x^2,x^3,x^4].

You are right---there's a shorter way. That's a form of VanDerMonde matrix:

c =

  124.500
  111.000
   88.900
   75.500
   63.000

octave:67> vander (c)
ans =

   2.4026e+08   1.9298e+06   1.5500e+04   1.2450e+02   1.0000e+00
   1.5181e+08   1.3676e+06   1.2321e+04   1.1100e+02   1.0000e+00
   6.2461e+07   7.0260e+05   7.9032e+03   8.8900e+01   1.0000e+00
   3.2493e+07   4.3037e+05   5.7002e+03   7.5500e+01   1.0000e+00
   1.5753e+07   2.5005e+05   3.9690e+03   6.3000e+01   1.0000e+00

vander (c)\b  does indeed give the same result as the full matrix

   -1.0222e-05
    3.5786e-03
   -5.0372e-01
    2.9366e+01
   -2.6907e+02



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

RE: solving equation system

HALL, BENJAMIN            PW
In reply to this post by Brigitte Diekhaus
I'm not sure how to change the output format.  One work-around is to do it
manually

sprintf('\n%15.5e',coeffs)

but maybe someone on the list has some additional suggestions?



-----Original Message-----
From: Brigitte Diekhaus [mailto:[hidden email]]
Sent: Thursday, April 21, 2005 6:29 AM
To: 'Hall, Benjamin'
Subject: AW: solving equation system


Thank you very much for your help!

I like this solution, because this way is very short!

I tried it and I got a new problem. My result is as follows:

coeffs =

1.0e+02 *

 -0.00000
  0.00004
 -0.00504
  0.29366
 -2.69074

I don`t like that the program multyplies the complete vector with the value
1.0e+02 I would like the writing you have:

   -1.0222e-05
    3.5786e-03
   -5.0372e-01
    2.9366e+01
   -2.6907e+02

Do you know how I can change this?

With best regards

Brigitte Diekhaus


-----Urspr√ľngliche Nachricht-----
Von: Hall, Benjamin [mailto:[hidden email]]
Gesendet: Dienstag, 19. April 2005 20:06
An: 'Madhusudan Singh'; [hidden email]
Cc: [hidden email]
Betreff: RE: solving equation system


It looks like you're trying to fit a 4th-order polynomial to the data

xx = [124.5; 111;    88.9;  75.5;  63  ];
yy = [ 29.3; 126.7; 236.4; 284.7; 315.5];

which you can do using polyfit

coeffs = polyfit( xx, yy, 4 )

coeffs =

   -1.0222e-05
    3.5786e-03
   -5.0372e-01
    2.9366e+01
   -2.6907e+02



-----Original Message-----
From: Madhusudan Singh [mailto:[hidden email]]
Sent: Tuesday, April 19, 2005 1:52 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: solving equation system


Looks simple. Define a coefficient matrix and solve it :

octave:6>
a=[1,124.5,124.5^2,124.5^3,124.5^4;1,111,111^2,111^3,111^4;1,88.9,88.9^2,88.
9^3,88.9^4;1,75.5,75.5^2,75.5^3,75.5^4;1,63,63^2,63^3,63^4]
a =

   1.0000e+00   1.2450e+02   1.5500e+04   1.9298e+06   2.4026e+08
   1.0000e+00   1.1100e+02   1.2321e+04   1.3676e+06   1.5181e+08
   1.0000e+00   8.8900e+01   7.9032e+03   7.0260e+05   6.2461e+07
   1.0000e+00   7.5500e+01   5.7002e+03   4.3037e+05   3.2493e+07
   1.0000e+00   6.3000e+01   3.9690e+03   2.5005e+05   1.5753e+07

octave:7> f=[29.3,126.7,236.4,284.7,315.5]'
f =

   29.300
  126.700
  236.400
  284.700
  315.500

octave:8> a\f
ans =

   -2.6907e+02
    2.9366e+01
   -5.0372e-01
    3.5786e-03
   -1.0222e-05

I hope that someone can point out a shorter way to define the coefficient
matrix since all its rows are of the form [1,x,x^2,x^3,x^4].

HTH

On Tuesday 19 April 2005 12:15, Brigitte Diekhaus wrote:

> hello,
>
> it`s my first time using octave and I want to solve the following equation
> system:
>
> 29.3 = A*124.5^4+B*124.5^3+C*124.5^2+124.5*D+F,
> 126.7 = A*111^4+B*111^3+C*111^2+D*111+F,
> 236.4 = A*88.9^4+B*88.9^3+C*88.9^2+D*88.9+F,
> 284.7 = A*75.5^4+B*75.5^3+C*75.5^2+D*75.5+F,
> 315.5 = A*63^4+B*63^3+C*63^2+D*63+F },
>
> I need to find the variables {A,B,C,D,F}
>
> to get a function like this:
>
> y(x)=a*x^4+b*x^3+c*x^2+d*x+e
>
> I Don`t know the syntax I have to use with octave to solve this equation
> system.
>
> many thanks in advance.
>
> Brigitte
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

RE: solving equation system

John W. Eaton-6
On 21-Apr-2005, Brigitte Diekhaus <[hidden email]> wrote:

| I tried it and I got a new problem. My result is as follows:
|
| coeffs =
|
| 1.0e+02 *
|
|  -0.00000
|   0.00004
|  -0.00504
|   0.29366
|  -2.69074
|
| I don`t like that the program multyplies the complete vector with the value
| 1.0e+02 I would like the writing you have:
|
|    -1.0222e-05
|     3.5786e-03
|    -5.0372e-01
|     2.9366e+01
|    -2.6907e+02
|
| Do you know how I can change this?

What version of Octave are you using?  Are you starting it with the
--traditional option because you think you want the most complete
Matlab compatibility?  Or maybe the binary distribution that you are
using did that for you?  If so, maybe you should omit the
--traditional option, or you can set the built-in variable
fixed_point_output to 0.

jwe





-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------