Understanding the algorithm for Newton Fractals [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I am having trouble understanding the equation for newton fractals. My professor gave a a general format to follow, but it is still coming out a bit confusing when I am reading over it. I was wondering if anyone can help clarify or simplify what he is talking about. So the parts I am most confused with is
Whatis the 'a'?
What are the conditions for the loop and why would I be resetting counter if it is my condition to leave the loop?
Is (x, y) the (real, imaginary) part of the complex number?
This is the picture of the algorithm he gave: https://i.stack.imgur.com/UJH41.jpg

What is the 'a'?
A complex number that generalizes the formula. Choose 1 for a Newton iteration.
What are the conditions for the loop and why would I be resetting counter if it is my condition to leave the loop?
You seem to miss the fact that you are trying to generate an image, setting the color of each pixel.
So, you have two nested loops that scan the pixels and, for each pixel, a loop that iterates the formula. That's the one that resets the counter and the initial value of z each time.
The condition of that loop are clearly expressed after this statement:
The iteration should continue while each of the following conditions is true.
Basically they limit the number of iterations and extablish a minimum tolerance. Note that z1, z2 and z3 are the roots of the third degree polynomial.
Is (x, y) the (real, imaginary) part of the complex number?
Not quite. The values of x and y are the coordinates of the pixels in the resulting image and are used to generate the real and imaginary part of the intitial value of z.
More details are probably written in the previous page, that you haven't posted.

Related

Solving system of equation modulo 2 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I make a program in C++, that factorizes natural numbers. The only problem is to create a function that does the following:
input: it receives a matrix vector< vector< int> > M.
output: it gives a vector v so that a result of multiplying v and M is a vector that all its coordinates are equal to 0.
Everything must be modulo 2, so coefficients of M and v consists only 0s and 1s
Schould I use a Gauss elimination method? If so, how do this? The problem that implementations I saw on the net don't use vectors and the vectors are necessary in my main program
I would be grateful if someone helped me.
Regards
This is an interesting problem. The steps to be taken can be found in this exercise. link.
The tricky part is to understand that there are always only a finite number of solutions, i.e, only the trivial solution exists or non-trivial solutions exist.
Once you finish the row reduction steps and if non-trivial solutions exist, there is always going to be at least one independent variable (it can take any value 0/1) and the rest of the variables depend on the independent variables.

Why is 2D array accessor [Column][Row] and not [Row][Column] format? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
This might be a dumb question but I spend too long not knowing reason.
All through out math classes we learn to put co-ordinates in (x, y) fashion. And it sticks into our minds. Now enter C/C++ and to access x=0, y=3 element, I have to do data[0][3] instead of data[3][0].
Why array accessing is (y, x) format and not (x, y)?
Is there particular reason for this or is it something that I just have to accept and move on with my life?
Edit:
I was watching this GDC talk by Mike Acton, (http://gdcvault.com/play/1021866/Code-Clinic-2015-How-to) where he talks about performance regarding row major access and column major access. Its understandable since any Array is sequential memory, its takes time to jump to different memory location if i'm trying to do column major access.
The [row][col] convention makes since when you look at the conventions used mathematics. Think about and order pair from algebra: (x, y) where the x comes first. This is consistent in math until you get all the way to linear algebra where the order suddenly changes. When dealing with matrices the up-down element should come first as in: M[row][col]. This convention is used in linear algebra for constancy in higher level operations like matrix multiplication...or multiplying a 3x3 matrix by a 3 vector (or 3x1 matrix). If you think of it like a matrix of discrete values instead of a point it makes since.

How to get common factors with c++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm having trouble starting with the code i have already read some other questions here but im still stuck on how am i even gonna start this one :/.
So i made 3 inputs to fill the expression (ax^2+bx+c)
.......
cout<<"This Program runs onlyy the expression (ax^2+bx+c)"<<endl;
cout<<"\nEnter The first Integer[a]";
cin>>ina;
cout<<"Enter the second Integer[b]";
cin>>inb;
cout<<"Enter The third Integer[c]";
cin>>inc;
cout<<"Your Expression is"<<endl;
cout<<ina<<"x^2 + "<<inb<<"x + "<<inc<<endl;
........
Now how would i make my program show its common factor..
example is (x^2+4x+3) how can i make it show that its common factor is (x+3) and (x+1)?
Well how to factor a polynomial has very little to do with C++.
If Ax^2 + Bx + C can be expressed as A*(x - x1)*(x - x2) (and it can always be so expressed), then clearly plugging the value x1 in for x makes the original equation zero, since the first term of (x1 - x1)*(x1 - x2) is then 0. And ditto for x2. And conversely, if you have two values that make the equation zero, then they are x1 and x2.
There is a standard formula for solving quadratic equations. Computing that in a program one should be aware that subtracting a number from a roughly equal size number can produce a less precise result. So how that formula is expressed in the code, can make a difference wrt. to the accuracy of the results. You can find more information about that on the net. Including examples for quadratic equation formula.

C++ comparing two value to find which is closest to user input value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have been looking on the internets for a while to find a solution to my problem. First some back ground. I'm writing a program that calculates catapult trajectory. The user must first type in a distance. Then I loop through the combinations of angle degrees and velocity to find which combination will give a distance that will come the closest to the users input. I don't quite know how to do the variable comparison to find which combination of degrees and velocity produces a distance closest to a users input of distance. I'm just trying to keep it simple and easy as possible. Also, I'm not using any kind of array to store the values. I want it done on the fly inside my for loops if possible. Any suggestions?
Well, the answer to this depends on the complexity of your trajectory formula. I'm guessing that you're not taking fluid dynamics or gravity differentials into consideration. In fact, what I imagine is that you're using a basic parabolic equation...
That equation can be solved directly by rearranging. But the thing is, you're solving for two variables that are actually co-dependent. There are infinite solutions if you allow both angle and velocity to vary, so you need to restrict the 'best' answer by some criteria (for example, desired angle or desired velocity).
If you have more variables, like lift, drag, spin, incident shape, non-constant gravity, air pressure and humidity, then you will need to employ a minimization algorithm which is non-trivial. One of the most basic, but a little unstable, is the Nelder-Mead algorithm.
If this has not been helpful enough, you should provide more information about your problem, and show some code.

Using induction to prove bubble sort is correct [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How can we show, using induction, that bubble sort is correct? How do we choose the invariant to follow throughout the formulation of the proof (this step seems like an arbitrary task to me, so if it can be explained more deeply I would greatly appreciate it)?
I understand that the largest elements will always end up at the end of the list after each iteration, but I don't know how to use this fact to show that the algorithm is correct.
Thanks for the help!
I am not sure if this is what you want, but his is how I see it.
The idea behind bubble sort is that you go though the vector of values (left to right). I am calling this a pass. During the pass pairs of values are checked and swapped to be in correct order (higher right).
During first pass the maximum value will be reached. When reached the max will be higher then value next to it, so they will be swapped. This means that max will become part of next pair in the pass. This repeats until pass is completed and max is left at the right end of the vector.
During second pass the same is true for the second highest value in the vector. Only difference is it will not be swapped with the max at the end. Now two most right values are correctly set.
I every next pass one value will be sorted out to the right.
There are N values and N passes. This means that after N passes all N values will be sorted