Test
Aus Wiki1
(Unterschied zwischen Versionen)
(Der Versionsvergleich bezieht 28 dazwischenliegende Versionen mit ein.) | |||
Zeile 1: | Zeile 1: | ||
- | < | + | <jsxgraph box="jxgbox" width="500" height="500"> |
+ | var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5,5,5,-5], axis:true}); | ||
- | < | + | // Define the metal plate as a polygon |
+ | var polygon = board.create('polygon', [[-4,-4], [-4,4], [4,4], [4,-4]], {fillcolor:'#ddd', hasInnerPoints:true}); | ||
+ | |||
+ | // Define the initial temperature distribution as a function of x and y | ||
+ | function initialTemp(x,y) { | ||
+ | return 20 + 10*Math.sin(Math.PI*x/4)*Math.sin(Math.PI*y/4); | ||
+ | } | ||
+ | |||
+ | // Define the temperature function as a function of x and y and time | ||
+ | function temp(x,y,t) { | ||
+ | var k = 1; | ||
+ | var c = 1; | ||
+ | var rho = 1; | ||
+ | var alpha = k/(rho*c); | ||
+ | return initialTemp(x,y) + 10*Math.exp(-alpha*Math.PI*Math.PI*t/16)*Math.sin(Math.PI*x/4)*Math.sin(Math.PI*y/4); | ||
+ | } | ||
+ | |||
+ | // Create a grid of points to sample the temperature function | ||
+ | var points = []; | ||
+ | for (var i=-4; i<=4; i+=0.5) { | ||
+ | for (var j=-4; j<=4; j+=0.5) { | ||
+ | points.push([i,j]); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Plot the temperature distribution at time t=0 | ||
+ | var heatmap = board.create('polygon', [points, initialTemp], {colorscheme:'greyscale', minopacity:0.5}); | ||
+ | |||
+ | // Animate the temperature distribution over time | ||
+ | var time = 0; | ||
+ | var dt = 0.1; | ||
+ | var interval = setInterval(function() { | ||
+ | time += dt; | ||
+ | var values = []; | ||
+ | for (var i=0; i<points.length; i++) { | ||
+ | values.push(temp(points[i][0], points[i][1], time)); | ||
+ | } | ||
+ | heatmap.updateData(values); | ||
+ | if (time >= 2) clearInterval(interval); | ||
+ | }, 100); | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
</jsxgraph> | </jsxgraph> |