+ 1

Using Python For Iterating With An Equation

Hey guys, please I'm quite new to python but I'd like to know exactly how I could use the syntax to model an equation which will have it's variables as a list of values to enable me iterate the equation through each variable value on the list. I don't know if that makes any sense to anyone but I'd really appreciate any support I can get.

15th Oct 2019, 10:49 PM
Chimezie Azih
7 Antworten
16th Oct 2019, 2:41 AM
Louis
Louis - avatar
+ 1
@Aymane Okay llet's say I have an equation 3x +2y - 1 = 2 and a list of values say [1,3,2,4,7,9,4] defined for the variable x, and a simiar list for the variable y. My intention is to write a body of code that helps iterate each of those values through the equation to provide individual answers to the expression, so that I can effectively extract the x and y values that produces a certain class of answer eg, if a particular x value and y value according to the predetermined list produces a resulting value above 50 when applied to the expression,, print the x and y values.
15th Oct 2019, 11:40 PM
Chimezie Azih
+ 1
My intention is to get appropriate values to plot a graph, but in order to do so, I would need to iterate a list of x and y variable values on an equation. I don't know if it's clearer now
15th Oct 2019, 11:42 PM
Chimezie Azih
+ 1
Why don't you write z=3x+2y-1-2 and next realiaze a double for cycle primary on the x vector and next on the y vector, with the intent to evaluate the z variable on the cartesian product of the vector x and y?
15th Oct 2019, 11:48 PM
Andrea Gambino
Andrea Gambino - avatar
+ 1
@Louis thanks for the code provided. That was exactly what I was looking for. Thanks also to all who provided their support. Bless
16th Oct 2019, 2:03 PM
Chimezie Azih
0
I don't really understand the question, can you give some examples ?
15th Oct 2019, 10:54 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
- 1
Hi. Do you want to solve an equation by iterative methods? In this case there are several different methods that you can implement. For example the Bisection method or the Newton-Raphson method. You should define a function that contains the mathematical Expression that you want to solve and next give x values and get y values. After that you should check the convergence of the two members of your equation with some If cycles. If you know c++ you can visit my personal codes that treat the topic. Good luck.
15th Oct 2019, 11:39 PM
Andrea Gambino
Andrea Gambino - avatar