Ask Your Question
1

Solve for integer and real number

asked 2025-01-01 21:41:46 +0100

sjondepon gravatar image

updated 2025-01-02 22:58:10 +0100

In a project I'm doing I stumbled on a way to solve something, but I don't know how I can excecute it. For simplicity I will ask an easier question analogue to how I want to solve mine.

Lets say we have a list of vectors:

L = [vector([1,0,0]), vector([0,1,0]), vector([0,0,1])]

I want to solve which vector multiplied by a constant would give me the vector([6,0,0])

I tried something like this:

var('x')
var('i', domain = 'integer')

solve([x * L[i] == vector([6,0,0])], i, x)

but it gives error "unable to convert i to integer" even though I explicitly stated that i is an integer.

Can someone please help me?

edit retag flag offensive close merge delete

Comments

Homework question?

Max Alekseyev gravatar imageMax Alekseyev ( 2025-01-03 04:25:00 +0100 )edit

No, I'm trying to find the distance I need to translate a 3-polytope in the 4th dimension, so that there if an overlap of a face of the original translated 3-polytope and a the translated 3-polytope rotated around 1 of its points. I don't know how the 3-polytope will rotate in the fourth dimension and thus which vectors will overlap, so I tried to put them into the equation.

sjondepon gravatar imagesjondepon ( 2025-01-03 12:15:29 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2025-01-03 16:31:43 +0100

tmonteil gravatar image

You can simply iterate over your list of vectors and search which vector gives a zero cross product with your target vector:

def search(L, target):
    for i,v in enumerate(L):
        if v.cross_product(target) == 0:
            return i
    raise ValueError('No vector found')

L = [vector([1,0,0]), vector([0,1,0]), vector([0,0,1])]
v= vector([6,0,0])

search(L, v)
0

search(L[1:], v)
ValueError: No vector found
edit flag offensive delete link more

Comments

Just a question, is it not possible to put integers in a solve function?

sjondepon gravatar imagesjondepon ( 2025-01-03 18:48:31 +0100 )edit

Also, in my computations, if it doesn't find a solution, the solve just keeps on going, is there a way to break the solve function if it calculated too long, so that i can go to the next iteration?

sjondepon gravatar imagesjondepon ( 2025-01-03 18:57:14 +0100 )edit

There is no sovle function in the given answer, so it's unclear what you are asking.

Max Alekseyev gravatar imageMax Alekseyev ( 2025-01-04 00:07:23 +0100 )edit

It should be possible to put integers into a solve function, but I don't know if it's possible to use solve for an index (solve for i so that L[i] has some property).

John Palmieri gravatar imageJohn Palmieri ( 2025-01-04 19:49:01 +0100 )edit

The alarm function can be used to interrupt computations.

John Palmieri gravatar imageJohn Palmieri ( 2025-01-04 19:50:21 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-01-01 21:41:46 +0100

Seen: 55 times

Last updated: yesterday