Re: solving an equation multiple directions



On Fri, 16 Jan 2009, Jason wrote:

I want to write a function in a computer language like C or Java.
I want the function to solve for one variable then another without
writing the equation twice.

Example:
x = y + z (given y and z)
y = x - z (given x and z)

but without writing two equations to prevent duplication in my code.
Any ideas?

Are you sure you want a function?
Perhaps you want a subroutine.
More likely you need clear thinking.

What input are you giving the function or subroutine?
An equation such as z = x + y ?

What output are you expecting?
More equations such as x = y - z and y = x - z ?

What do you mean without writing the code twice?
That's what functions and subroutines are used for,
to not repleat code at the additional time cost of
calling and returning from a function or subroutine.
.



Relevant Pages

  • Re: solving an equation multiple directions
    ... writing the equation twice. ... Perhaps you want a subroutine. ... What do you mean without writing the code twice? ... If the user inputs y and z, then the equation is solved as x = y + z. ...
    (sci.math)
  • Re: recurse subdirectories without using File::Find
    ... Why are you ignoring a known non-buggy solution in favor of ... You start by writing better code, and asking Perl for help whenever you ... Why are you calling the subroutine with the & on front? ...
    (perl.beginners)
  • Re: writing drivers using C++
    ... You are trying to sidestep the issue by writing about something ... coding against an interface - when the implementation starts mattering to ... Every subroutine invokation has to be coded manually, ...
    (comp.os.linux.development.system)
  • Re: [QUIZ][SOLUTION] Kalah (#58)
    ... preceding URL makes it look harder and more cumbersome than just writing a ... subroutine to exercise your new class. ...
    (comp.lang.ruby)
  • Re: use go to doing some case studies and induced problems
    ... these case studies are not so worthy of writing them as ... If for some reason I really didn't want a separate routine with an argument list, I'd use an internal subroutine. ... Anything so short that it's not worth making a subroutine for, I'd put inline in the code. ... I'd have to say, this sounds like it could easily lead to GIGO (garbage in, garbage out) when you miss something in the logic. ...
    (comp.lang.fortran)