get coordinates and function value as list

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

I am quite new in sage as well as in programming, so please if you explain this, please do it thouroughly.

Let's assume we have a simple function like F(x,y)=x+y. Is it possible to create a list, something like (x,y,F)? To make clearer a list in the form of (value_of_x_coordinate,value_of_y_coordinate,value_of_function) for instance (1,1,2) or (1,2,3). If this is possible, how can we transform the coordinates x,y by operating somehow on the list e.g adding on both x and y, a number N.

asked Jul 04 '12

Cosmos gravatar image Cosmos
1 2
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

List comprehension is a way of constructing lists that is very readable and concise. It mimics set builder notation from mathematics:

f(x,y) = x + y
L = [ (a, b, f(a, b)) for (a,b) in [ (0,0), (1,1), (5.6, 7.0) ] ]

or

L = [ (a, b, f(a, b)) for a in range(10) for b in range(10) ]

try these out and see what they produce.

You can now modify your list or add to it any way you want. For example:

f(x,y) = x + y
L = [ (a, b, f(a, b)) for (a,b) in [ (0,0), (1,1), (5.6, 7.0) ] ]
print L[0] # prints (0,0,0)
L[0] = (1,2, f(1,2))
print L[0] # prints (1,2,3)

L.append((1.1, 1.2, f(1.1, 1.2)))
print L[3]
link

posted Jul 04 '12

benjaminfjones gravatar image benjaminfjones
2470 3 33 66
http://bfj7.com/

Thank you for your reply. I think now i can make a more general question on the subject.When we ask sage to plot a function doesn't it replace (x,y) with values,it gets the values of the function and then plots it? Is there a way instead of asking from the program to plot the values it just calculated, to just create a list or some other construct with all the values (so that we don't have to create it ourselves each time)? Something like x_coordinates_column,y_coordinates_column,Function_value_column. Let's use this example: We have a f(x,y)=sin(x)cos(y) and we want the contours sin(x)cos(y)=k where k is a real number we can change as we like. I would like to have a consrtuct as described above with x_values,y_values,k.

Cosmos (Jul 05 '12)

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

1 follower

Tags:

Stats:

Asked: Jul 04 '12

Seen: 73 times

Last updated: Jul 04 '12

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.