# Difference between revisions of "N-th root"

From JSXGraph Wiki

Jump to navigationJump to searchA WASSERMANN (talk | contribs) |
A WASSERMANN (talk | contribs) |
||

(4 intermediate revisions by the same user not shown) | |||

Line 1: | Line 1: | ||

+ | This example shows the various possibilities to plot the graph of the function | ||

+ | |||

+ | :<math> \mathbb{R} \to \mathbb{R}, x \mapsto x^{1/3}</math> | ||

+ | |||

+ | also for negative values of <math>x</math>. | ||

+ | |||

+ | There are the following choices: | ||

+ | |||

+ | * "Math.pow(x, 1/3)": this built-in JavaScript function is restricted to positive values of <math>x</math>. | ||

+ | * "JXG.Math.cbrt(x)": cube root function which is able to compute the real cube root of <math>x</math>. It is available in most browsers as built-in "Math.cbrt()". The JSXGraph makes cbrt available also on old browsers. | ||

+ | * "JXG.Math.nthroot(x, 3)": general method in JSXGraph to compute the real <math>n</math>-th root of a real number. | ||

+ | |||

<jsxgraph width="500" height="500"> | <jsxgraph width="500" height="500"> | ||

var board = JXG.JSXGraph.initBoard('jxgbox', { | var board = JXG.JSXGraph.initBoard('jxgbox', { | ||

Line 12: | Line 24: | ||

name:'Math.pow(x, 1/3) - 1', | name:'Math.pow(x, 1/3) - 1', | ||

strokeColor: 'red', | strokeColor: 'red', | ||

− | label: {position: 'rt', offset:[-100, | + | label: {position: 'rt', offset:[-100,-20]} |

}); | }); | ||

</jsxgraph> | </jsxgraph> | ||

Line 18: | Line 30: | ||

===The underlying JavaScript code=== | ===The underlying JavaScript code=== | ||

<source lang="javascript"> | <source lang="javascript"> | ||

+ | var board = JXG.JSXGraph.initBoard('jxgbox', { | ||

+ | axis:true, | ||

+ | boundingbox:[-5, 5, 5, -5], | ||

+ | showFullscreen: true | ||

+ | }); | ||

+ | |||

+ | var plot1 = board.create('functiongraph', ["nthroot(x, 3)"], {withLabel: true, name:'nthroot(x,3)'}); | ||

+ | var plot2 = board.create('functiongraph', ["cbrt(x) + 1"], {withLabel: true, name:'cbrt(x)+1', strokeColor: 'black'}); | ||

+ | var plot3 = board.create('functiongraph', [(x) => Math.pow(x, 1/3) - 1], { | ||

+ | withLabel: true, | ||

+ | name:'Math.pow(x, 1/3) - 1', | ||

+ | strokeColor: 'red', | ||

+ | label: {position: 'rt', offset:[-100,-20]} | ||

+ | }); | ||

</source> | </source> | ||

[[Category:Examples]] | [[Category:Examples]] | ||

[[Category:Calculus]] | [[Category:Calculus]] |

## Latest revision as of 13:14, 2 April 2020

This example shows the various possibilities to plot the graph of the function

- [math] \mathbb{R} \to \mathbb{R}, x \mapsto x^{1/3}[/math]

also for negative values of [math]x[/math].

There are the following choices:

- "Math.pow(x, 1/3)": this built-in JavaScript function is restricted to positive values of [math]x[/math].
- "JXG.Math.cbrt(x)": cube root function which is able to compute the real cube root of [math]x[/math]. It is available in most browsers as built-in "Math.cbrt()". The JSXGraph makes cbrt available also on old browsers.
- "JXG.Math.nthroot(x, 3)": general method in JSXGraph to compute the real [math]n[/math]-th root of a real number.

### The underlying JavaScript code

```
var board = JXG.JSXGraph.initBoard('jxgbox', {
axis:true,
boundingbox:[-5, 5, 5, -5],
showFullscreen: true
});
var plot1 = board.create('functiongraph', ["nthroot(x, 3)"], {withLabel: true, name:'nthroot(x,3)'});
var plot2 = board.create('functiongraph', ["cbrt(x) + 1"], {withLabel: true, name:'cbrt(x)+1', strokeColor: 'black'});
var plot3 = board.create('functiongraph', [(x) => Math.pow(x, 1/3) - 1], {
withLabel: true,
name:'Math.pow(x, 1/3) - 1',
strokeColor: 'red',
label: {position: 'rt', offset:[-100,-20]}
});
```