c++ sequence calculator x_n+1 = f (x_n) = (1/7)∗((x_n^3)+2)Fibonacci sequence implementationGrade point average (GPA) calculatorCourse Grade CalculatorAlgebraic calculatorChange calculatorHackerRank: XOR-sequenceTerminal ESC Sequence DecoderSimple Calculator AppsBetter Fibonacci sequence calculationSigma calculator
What should you do if you miss a job interview (deliberately)?
Is it safe to use olive oil to clean the ear wax?
Why Shazam when there is already Superman?
Why should universal income be universal?
What are the purposes of autoencoders?
What does chmod -u do?
Must Legal Documents Be Siged In Standard Pen Colors?
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
On a tidally locked planet, would time be quantized?
Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?
Where does the bonus feat in the cleric starting package come from?
Why is so much work done on numerical verification of the Riemann Hypothesis?
Is it better practice to read straight from sheet music rather than memorize it?
Not using 's' for he/she/it
C++ debug/print custom type with GDB : the case of nlohmann json library
The screen of my macbook suddenly broken down how can I do to recover
Reverse int within the 32-bit signed integer range: [−2^31, 2^31 − 1]
Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed
Fear of getting stuck on one programming language / technology that is not used in my country
Why is it that I can sometimes guess the next note?
Creepy dinosaur pc game identification
What prevents the use of a multi-segment ILS for non-straight approaches?
What was this official D&D 3.5e Lovecraft-flavored rulebook?
Non-trope happy ending?
c++ sequence calculator x_n+1 = f (x_n) = (1/7)∗((x_n^3)+2)
Fibonacci sequence implementationGrade point average (GPA) calculatorCourse Grade CalculatorAlgebraic calculatorChange calculatorHackerRank: XOR-sequenceTerminal ESC Sequence DecoderSimple Calculator AppsBetter Fibonacci sequence calculationSigma calculator
$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$
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$
$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
2 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
2 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
2 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 11 mins ago
ness
New contributor
asked 3 hours ago
nessness
11
11
New contributor
New contributor
$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
2 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
2 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
2 hours ago
add a comment |
$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
2 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
2 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
2 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
2 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
2 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
2 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
2 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
2 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
2 hours ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
ness is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216078%2fc-sequence-calculator-x-n1-f-x-n-1-7%25e2%2588%2597x-n32%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
ness is a new contributor. Be nice, and check out our Code of Conduct.
ness is a new contributor. Be nice, and check out our Code of Conduct.
ness is a new contributor. Be nice, and check out our Code of Conduct.
ness is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216078%2fc-sequence-calculator-x-n1-f-x-n-1-7%25e2%2588%2597x-n32%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$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
2 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
2 hours ago
$begingroup$
editted to working code.
$endgroup$
– ness
2 hours ago