help-octave
[Top][All Lists]
Advanced

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

Re: Newbie question on solving simple equations


From: Ivan Sutoris
Subject: Re: Newbie question on solving simple equations
Date: Tue, 19 May 2009 17:09:20 +0200

On Tue, May 19, 2009 at 4:45 PM, Joe Kirchner <address@hidden> 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



reply via email to

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