c++ sequence calculator x_{n+1} = f (x_n) = (1/7)∗((x_n^3)+2) [on hold]
$begingroup$
example of code
#include <iostream>
using namespace std;
//whitespace package
#include <iomanip>
#include <math.h>
using std::setw;
int main () {
// n is an array of 101 integers
long double n[ 101 ];
double exponent=3;
double fraction=1.0/7;
// initialize elements of array n to 0
for ( int i = 1; i < 100; i++ ) {
n[ i ] = 0;
}
//what is input 1?
cout << "Enter x_1" << endl;
cin >> n[1];
//jam ni's into function and loop
for ( int i = 1; i < 100; i++ ) {
// set element at location i+1 to f(x)= (fraction)*((x)^exponent + 2)
n[ i + 1 ] = fraction*(pow( ((n[ i ]) ), exponent ) + 2);
}
//header
cout << "Element" << setw( 13 ) << "Value" << endl;
// output each array element's value
for ( int j = 1; j < 100; j++ ) {
cout << setw( 7 )<< j << setw( 13 ) << n[ j ] << endl;
}
return 0;
}
output
Element Value
1 1
2 0.42857142857
3 0.29695960016
4 0.2894553405
5 0.28917883433
6 0.28916891514
7 0.28916855966
...
background: I'm trying to write a simple program that asks what your $x_1$ is and reports $x_1$ to $x_{100}$ given some series function calculator--like a sequence calculator where $x_{n+1} = f(x_n)$. In this example, our function is (1/7)*((x)^3 + 2).
Can you all offer some resources for writing other functions? I have $x_{n+1}=f(x_n)=(1/7)*((x_n^3)+2)$ right now.
Whenever I look up c++ math functions I get things like how to use the absolute value function, or how to use my cpp file as a function itself, but not information on writing math functions like this.
c++
New contributor
$endgroup$
put on hold as off-topic by vnp, 200_success, Jamal♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – vnp, 200_success, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
example of code
#include <iostream>
using namespace std;
//whitespace package
#include <iomanip>
#include <math.h>
using std::setw;
int main () {
// n is an array of 101 integers
long double n[ 101 ];
double exponent=3;
double fraction=1.0/7;
// initialize elements of array n to 0
for ( int i = 1; i < 100; i++ ) {
n[ i ] = 0;
}
//what is input 1?
cout << "Enter x_1" << endl;
cin >> n[1];
//jam ni's into function and loop
for ( int i = 1; i < 100; i++ ) {
// set element at location i+1 to f(x)= (fraction)*((x)^exponent + 2)
n[ i + 1 ] = fraction*(pow( ((n[ i ]) ), exponent ) + 2);
}
//header
cout << "Element" << setw( 13 ) << "Value" << endl;
// output each array element's value
for ( int j = 1; j < 100; j++ ) {
cout << setw( 7 )<< j << setw( 13 ) << n[ j ] << endl;
}
return 0;
}
output
Element Value
1 1
2 0.42857142857
3 0.29695960016
4 0.2894553405
5 0.28917883433
6 0.28916891514
7 0.28916855966
...
background: I'm trying to write a simple program that asks what your $x_1$ is and reports $x_1$ to $x_{100}$ given some series function calculator--like a sequence calculator where $x_{n+1} = f(x_n)$. In this example, our function is (1/7)*((x)^3 + 2).
Can you all offer some resources for writing other functions? I have $x_{n+1}=f(x_n)=(1/7)*((x_n^3)+2)$ right now.
Whenever I look up c++ math functions I get things like how to use the absolute value function, or how to use my cpp file as a function itself, but not information on writing math functions like this.
c++
New contributor
$endgroup$
put on hold as off-topic by vnp, 200_success, Jamal♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – vnp, 200_success, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
1
$begingroup$
((n[i]) + 2)^2
does a bitwise XOR of((n[i]+2)
with2
, not exponentiation. However, this question is off-topic for Code Review because the code does not work as you intend.
$endgroup$
– esote
6 hours ago
$begingroup$
okay sorry about that. Tahnkyou so much for pointing out my error. Could you refer me to a site/stack exchange where I can get help with my code?
$endgroup$
– ness
6 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
5 hours ago
add a comment |
$begingroup$
example of code
#include <iostream>
using namespace std;
//whitespace package
#include <iomanip>
#include <math.h>
using std::setw;
int main () {
// n is an array of 101 integers
long double n[ 101 ];
double exponent=3;
double fraction=1.0/7;
// initialize elements of array n to 0
for ( int i = 1; i < 100; i++ ) {
n[ i ] = 0;
}
//what is input 1?
cout << "Enter x_1" << endl;
cin >> n[1];
//jam ni's into function and loop
for ( int i = 1; i < 100; i++ ) {
// set element at location i+1 to f(x)= (fraction)*((x)^exponent + 2)
n[ i + 1 ] = fraction*(pow( ((n[ i ]) ), exponent ) + 2);
}
//header
cout << "Element" << setw( 13 ) << "Value" << endl;
// output each array element's value
for ( int j = 1; j < 100; j++ ) {
cout << setw( 7 )<< j << setw( 13 ) << n[ j ] << endl;
}
return 0;
}
output
Element Value
1 1
2 0.42857142857
3 0.29695960016
4 0.2894553405
5 0.28917883433
6 0.28916891514
7 0.28916855966
...
background: I'm trying to write a simple program that asks what your $x_1$ is and reports $x_1$ to $x_{100}$ given some series function calculator--like a sequence calculator where $x_{n+1} = f(x_n)$. In this example, our function is (1/7)*((x)^3 + 2).
Can you all offer some resources for writing other functions? I have $x_{n+1}=f(x_n)=(1/7)*((x_n^3)+2)$ right now.
Whenever I look up c++ math functions I get things like how to use the absolute value function, or how to use my cpp file as a function itself, but not information on writing math functions like this.
c++
New contributor
$endgroup$
example of code
#include <iostream>
using namespace std;
//whitespace package
#include <iomanip>
#include <math.h>
using std::setw;
int main () {
// n is an array of 101 integers
long double n[ 101 ];
double exponent=3;
double fraction=1.0/7;
// initialize elements of array n to 0
for ( int i = 1; i < 100; i++ ) {
n[ i ] = 0;
}
//what is input 1?
cout << "Enter x_1" << endl;
cin >> n[1];
//jam ni's into function and loop
for ( int i = 1; i < 100; i++ ) {
// set element at location i+1 to f(x)= (fraction)*((x)^exponent + 2)
n[ i + 1 ] = fraction*(pow( ((n[ i ]) ), exponent ) + 2);
}
//header
cout << "Element" << setw( 13 ) << "Value" << endl;
// output each array element's value
for ( int j = 1; j < 100; j++ ) {
cout << setw( 7 )<< j << setw( 13 ) << n[ j ] << endl;
}
return 0;
}
output
Element Value
1 1
2 0.42857142857
3 0.29695960016
4 0.2894553405
5 0.28917883433
6 0.28916891514
7 0.28916855966
...
background: I'm trying to write a simple program that asks what your $x_1$ is and reports $x_1$ to $x_{100}$ given some series function calculator--like a sequence calculator where $x_{n+1} = f(x_n)$. In this example, our function is (1/7)*((x)^3 + 2).
Can you all offer some resources for writing other functions? I have $x_{n+1}=f(x_n)=(1/7)*((x_n^3)+2)$ right now.
Whenever I look up c++ math functions I get things like how to use the absolute value function, or how to use my cpp file as a function itself, but not information on writing math functions like this.
c++
c++
New contributor
New contributor
edited 3 hours ago
ness
New contributor
asked 7 hours ago
nessness
61
61
New contributor
New contributor
put on hold as off-topic by vnp, 200_success, Jamal♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – vnp, 200_success, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by vnp, 200_success, Jamal♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – vnp, 200_success, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
1
$begingroup$
((n[i]) + 2)^2
does a bitwise XOR of((n[i]+2)
with2
, not exponentiation. However, this question is off-topic for Code Review because the code does not work as you intend.
$endgroup$
– esote
6 hours ago
$begingroup$
okay sorry about that. Tahnkyou so much for pointing out my error. Could you refer me to a site/stack exchange where I can get help with my code?
$endgroup$
– ness
6 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
5 hours ago
add a comment |
1
$begingroup$
((n[i]) + 2)^2
does a bitwise XOR of((n[i]+2)
with2
, not exponentiation. However, this question is off-topic for Code Review because the code does not work as you intend.
$endgroup$
– esote
6 hours ago
$begingroup$
okay sorry about that. Tahnkyou so much for pointing out my error. Could you refer me to a site/stack exchange where I can get help with my code?
$endgroup$
– ness
6 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
5 hours ago
1
1
$begingroup$
((n[i]) + 2)^2
does a bitwise XOR of ((n[i]+2)
with 2
, not exponentiation. However, this question is off-topic for Code Review because the code does not work as you intend.$endgroup$
– esote
6 hours ago
$begingroup$
((n[i]) + 2)^2
does a bitwise XOR of ((n[i]+2)
with 2
, not exponentiation. However, this question is off-topic for Code Review because the code does not work as you intend.$endgroup$
– esote
6 hours ago
$begingroup$
okay sorry about that. Tahnkyou so much for pointing out my error. Could you refer me to a site/stack exchange where I can get help with my code?
$endgroup$
– ness
6 hours ago
$begingroup$
okay sorry about that. Tahnkyou so much for pointing out my error. Could you refer me to a site/stack exchange where I can get help with my code?
$endgroup$
– ness
6 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
5 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
5 hours ago
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
$begingroup$
((n[i]) + 2)^2
does a bitwise XOR of((n[i]+2)
with2
, not exponentiation. However, this question is off-topic for Code Review because the code does not work as you intend.$endgroup$
– esote
6 hours ago
$begingroup$
okay sorry about that. Tahnkyou so much for pointing out my error. Could you refer me to a site/stack exchange where I can get help with my code?
$endgroup$
– ness
6 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
5 hours ago