Quantcast

Newbie question on solving simple equations

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Newbie question on solving simple equations

Joe_K
Hi,

I just installed Octave and thought I would give it a try.

I tried to solve a trivial equation:

8 = 2 * x + 4

what is x?

When I type the equation, Octave complains that x is undefined.  The only way I can get Octave to solve for x is to do half the work myself by transforming the equation, such that x is alone on the left side of the equation:

x = (8 - 4) / 2

Only then does Octave reply that:

x = 2

How do I give Octave an equation or a set of equations and then ask it to solve them? 

A slightly less trivial example is:

10 = x * y + 2
8 = 2 * y + x

what are x and y?

In this case, I could not transform the equations as above because the transformation of the first equation to x = ... is not resolvable without the second equation, so it would complain that y is undefined. And if I transformed it to y =  ..., it would complain that x is undefined.  In this case, (before the second equation is defined) x and y are unknowable.  So what syntax do I use to submit both equations simultaneously to Octave, so that it can solve these simultaneously?

Of course, I could transform the equations and use substitution, but again I would be doing half the work by hand.

I have scanned through the help documentation, but such simple issues are not addressed.

Can anyone give me a few examples of syntax I would submit to address these trivial equations?

Thanks,

Joe

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Newbie question on solving simple equations

Jaroslav Hajek-2
On Tue, May 19, 2009 at 4:45 PM, Joe Kirchner <[hidden email]> wrote:

> Hi,
>
> I just installed Octave and thought I would give it a try.
>
> I tried to solve a trivial equation:
>
> 8 = 2 * x + 4
>
> what is x?
>
> When I type the equation, Octave complains that x is undefined.  The only
> way I can get Octave to solve for x is to do half the work myself by
> transforming the equation, such that x is alone on the left side of the
> equation:
>
> x = (8 - 4) / 2
>
> Only then does Octave reply that:
>
> x = 2
>
> How do I give Octave an equation or a set of equations and then ask it to
> solve them?
>
> A slightly less trivial example is:
>
> 10 = x * y + 2
> 8 = 2 * y + x
>
> what are x and y?
>
> In this case, I could not transform the equations as above because the
> transformation of the first equation to x = ... is not resolvable without
> the second equation, so it would complain that y is undefined. And if I
> transformed it to y =  ..., it would complain that x is undefined.  In this
> case, (before the second equation is defined) x and y are unknowable.  So
> what syntax do I use to submit both equations simultaneously to Octave, so
> that it can solve these simultaneously?
>
> Of course, I could transform the equations and use substitution, but again I
> would be doing half the work by hand.
>
> I have scanned through the help documentation, but such simple issues are
> not addressed.
>
> Can anyone give me a few examples of syntax I would submit to address these
> trivial equations?
>
> Thanks,
>
> Joe
>

Octave is not a CAS, which is what you apparently want, but rather a
numerical tool. It can solve equations (linear, nonlinear) only
approximately, and needs them specified in some canonical form.

For more info, see:
http://en.wikipedia.org/wiki/Computer_algebra_system

regards

--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Newbie question on solving simple equations

Ivan Sutoris
In reply to this post by Joe_K
On Tue, May 19, 2009 at 4:45 PM, Joe Kirchner <[hidden email]> wrote:

> Hi,
>
> I just installed Octave and thought I would give it a try.
>
> I tried to solve a trivial equation:
>
> 8 = 2 * x + 4
>
> what is x?
>
> When I type the equation, Octave complains that x is undefined.  The only
> way I can get Octave to solve for x is to do half the work myself by
> transforming the equation, such that x is alone on the left side of the
> equation:
>
> x = (8 - 4) / 2
>
> Only then does Octave reply that:
>
> x = 2
>
> How do I give Octave an equation or a set of equations and then ask it to
> solve them?
>
> A slightly less trivial example is:
>
> 10 = x * y + 2
> 8 = 2 * y + x
>
> what are x and y?
>
> In this case, I could not transform the equations as above because the
> transformation of the first equation to x = ... is not resolvable without
> the second equation, so it would complain that y is undefined. And if I
> transformed it to y =  ..., it would complain that x is undefined.  In this
> case, (before the second equation is defined) x and y are unknowable.  So
> what syntax do I use to submit both equations simultaneously to Octave, so
> that it can solve these simultaneously?
>
> Of course, I could transform the equations and use substitution, but again I
> would be doing half the work by hand.
>
> I have scanned through the help documentation, but such simple issues are
> not addressed.
>
> Can anyone give me a few examples of syntax I would submit to address these
> trivial equations?
>
> Thanks,
>
> Joe

Hi

Octave is a programming language, so it can't "magically" solve any
equation you enter. In fact, "=" is used for assignment, not equality,
so your example "8 = 2 * x + 4" is interpreted as "compute 2*x+4 and
assign it to 8", which does not make sense (since x is undefined and 8
is a constant). On the other hand, "x = (8 - 4) / 2" is valid since
right side is a mathematical expression that is evaluated to a number,
which is then assigned to variable x.

I hope this made some sense, I suggest you take look at chapter 1 of
Octave manual ("A Brief Introduction to Octave") which gives some
simple examples. To solve set of linear equations Ax = b (written in
matrix form), you must specify matrix A, vector b and then solve by "x
= A\b". For nonlinear equations, you must use "fsolve" function.

Regards
Ivan Sutoris

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Newbie question on solving simple equations

Francesco Potortì
In reply to this post by Joe_K
>I tried to solve a trivial equation:
>
>8 = 2 * x + 4
>
>what is x?

You want symbolic equation solving.  Octave is not made for it, event
though it has an optional symbolic package that can do some symbolic
computations.  However this makes sense only if you use Octave for what
it does best, that is numeric computations, and you need the occasional
symbolic computation.

For a symbolic package, you could try Maxima.

--
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: [hidden email]
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Loading...