I want to calculate several floating point functions that are a function of two variables, i.e. a(x,y), b(x,y) etc. x and y can be represented as x=idelx and y=jdely. So a(i,j) or b(i,j) is what I would actually calculate. How do I code a and b as functions of i and j for various i and j values?

Recommended Answers

All 4 Replies

First off, you should understand that a Python function is not a function in the mathematical sense of a relationship between a set of values n<sub>x</sub> in a domain and a value m in a co-domain. Rather, it is a series of expressions that perform a computation, and may or may not return a value. This can be confusing, if you are coming from a mathematical background.

Also, there is a keyword del in Python that has nothing to do with the three functions variously given that name. You'll want to define your own curl(), gradient() or divergence() function to compute the value in question.

Are the two values x and y actually the vector <x,y>? If so, you would do well to define a vector class, if you know how to. If not, you can use lists to pass the vectors around as a unit. Thus, you would actually define your function as taking three parameters, something like this:

def a(vec, i, j):
    vec[0] = grad(i, x)
    vec[1] = grad(j, y)
    return vec

As I say, though, a class would actually be preferable:

class Vector(Object):
    def __init__(self, x, y):
        self.__x = x
        self.__y = y

    def __str__(self):
        return '<{x},{y}>'.format(x=self.__x, y=self.__y)

    def a(self, i, j):
        x = grad(i, self.__x)
        y = grad(j, self.__y)
        return Vector(x, y)  # return a new vector

    def b(self, i, j):
        # put your function definition here

if __name__ == "__main__":
    vec = Vector(2.0, 7.5)
    new_vec = vec.a(3.3, 4.5)

Of course, this is assuming that you are really working with 2-dimensional vectors, and that the function you are performing on the vector components is gradient.

write a code fragment for the flow chart .assume that the varibles x and y are integers and z is a floating-point number.thanks i need the answer right now.please.


Don't go hijacking other people's threads. Don't go dropping your homework on us without any context. And most of all, don't go demanding code for a project you are supposed to be doing.

We are a patient and, for the most part, helpful group here. Helping you fix problems with your code is what we are here for. So is helping you improve your programming skills. Helping you cheat isn't part of the deal.

With the attitude you are giving in just this one post, I doubt anyone here will ever respond to you unless you make some contrite apologies right away.

@Anicia ... if you do really wish help, on your Python coding problem, please start a new thread and show what work (and code) that you have so far ... in the direction of solving the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.