Difference between revisions of "P-Norm"

From JSXGraph Wiki
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<jsxgraph width="500" height="500">
 
<jsxgraph width="500" height="500">
 
var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-5,5,5,-5]});
 
var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-5,5,5,-5]});
var pNorm = brd.create('slider', [[0,-1],[3,-1],[0,2,10]], {name:'p'});
+
var pNorm = brd.create('slider', [[0,4],[3,4],[0,2,10]], {name:'p'});
 +
var m = brd.create('point',[0,0], {name:'M'});
 
graph = brd.create('curve', [
 
graph = brd.create('curve', [
 
   function(t){
 
   function(t){
Line 8: Line 9:
 
                 Math.pow(Math.abs(Math.sin(t)),p),1.0/p);
 
                 Math.pow(Math.abs(Math.sin(t)),p),1.0/p);
 
   },
 
   },
   [0,0],  
+
   [function(){ return m.X();}, function(){ return m.Y();}],  
 
   0, Math.PI*2],  
 
   0, Math.PI*2],  
 
   {curveType:'polar',strokeColor:'red', strokeWidth:2}
 
   {curveType:'polar',strokeColor:'red', strokeWidth:2}
Line 15: Line 16:
  
 
===The underlying JavaScript code===
 
===The underlying JavaScript code===
 +
<source lang="javascript">
 +
var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-5,5,5,-5]});
 +
var pNorm = brd.create('slider', [[0,4],[3,4],[0,2,10]], {name:'p'});
 +
var m = brd.create('point',[0,0], {name:'M'});
 +
graph = brd.create('curve', [
 +
  function(t){
 +
      var p = pNorm.Value();
 +
      return 2.0/Math.pow(Math.pow(Math.abs(Math.cos(t)),p)+
 +
                Math.pow(Math.abs(Math.sin(t)),p),1.0/p);
 +
  },
 +
  [function(){ return m.X();}, function(){ return m.Y();}],
 +
  0, Math.PI*2],
 +
  {curveType:'polar',strokeColor:'red', strokeWidth:2}
 +
  );
 +
</source>
  
 
[[Category:Examples]]
 
[[Category:Examples]]
 
[[Category:Calculus]]
 
[[Category:Calculus]]

Latest revision as of 22:45, 1 July 2010

The underlying JavaScript code

var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-5,5,5,-5]});
var pNorm = brd.create('slider', [[0,4],[3,4],[0,2,10]], {name:'p'});
var m = brd.create('point',[0,0], {name:'M'});
graph = brd.create('curve', [
   function(t){
      var p = pNorm.Value();
      return 2.0/Math.pow(Math.pow(Math.abs(Math.cos(t)),p)+
                Math.pow(Math.abs(Math.sin(t)),p),1.0/p);
   },
   [function(){ return m.X();}, function(){ return m.Y();}], 
   0, Math.PI*2], 
   {curveType:'polar',strokeColor:'red', strokeWidth:2}
   );