Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jcponce committed Jul 17, 2023
2 parents c4dfb7d + e7166c6 commit 70f4003
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 15 deletions.
2 changes: 1 addition & 1 deletion math1052/lecture-09.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ <h4>1 Ordinary Differential Equations</h4>
<p>

<span class="fragment" data-fragment-index="4">
<strong>Case 1: Two disticnt real roots</strong>
<strong>Case 1: Two distinct real roots</strong>
</span>


Expand Down
31 changes: 28 additions & 3 deletions math1052/lecture-10.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ <h4>1 Ordinary Differential Equations</h4>

<br/><br/><br/><br/><br/><br/>
</section>



</section>


<section>
<section data-auto-animate>
<h4>1 Ordinary Differential Equations</h4>
<div id="sbt">
Expand Down Expand Up @@ -486,7 +493,7 @@ <h4>1 Ordinary Differential Equations</h4>
</div>


<br/><br/>
<br/><br/><br/>
</section>
<section data-auto-animate>
<h4>1 Ordinary Differential Equations</h4>
Expand Down Expand Up @@ -883,8 +890,6 @@ <h4>1 Ordinary Differential Equations</h4>

<br/>
</section>


</section>


Expand Down Expand Up @@ -1584,6 +1589,26 @@ <h4>1 Ordinary Differential Equations</h4>
<br/><br/>
</section>

<section data-auto-animate>
<h4>1 Ordinary Differential Equations</h4>
<div id="sbt">
<p><strong>1.8 Simple Harmonic Motion and Damped Oscillations</strong></p>
</div>



<div style="margin-top:40px">
<iframe
scrolling="no"
style="width:600px; height: 400px;border:0px"
data-src="sketches/chapter-01/damped-oscillator/" >
</iframe>
</div>


<br/><br/><br/>
</section>

</section>


Expand Down
8 changes: 4 additions & 4 deletions math1052/lecture-11.html
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ <h4>1 Ordinary Differential Equations</h4>
</div>

<div>
<iframe scrolling="no" title="Underdamping" src="https://www.geogebra.org/material/iframe/id/tspgx7qr/width/772/height/474/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/asb/false/sri/true/rc/false/ld/false/sdz/true/ctl/true"
width="772px" height="474px" style="border:0px;" allowfullscreen=""> </iframe>
<iframe scrolling="no" title="L11: Underdamping" src="https://www.geogebra.org/material/iframe/id/rr8cmngt/width/772/height/474/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/asb/false/sri/true/rc/false/ld/false/sdz/true/ctl/false"
width="772px" height="474px" style="border:0px;" allowfullscreen=""> </iframe>
</div>

<br/><br/>
Expand Down Expand Up @@ -1142,7 +1142,7 @@ <h4>1 Ordinary Differential Equations</h4>
</div>

<div>
<iframe scrolling="no" title="Critical damping" src="https://www.geogebra.org/material/iframe/id/chn8pwwf/width/772/height/474/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/asb/false/sri/true/rc/false/ld/false/sdz/true/ctl/true"
<iframe scrolling="no" title="L11: Critical damping" src="https://www.geogebra.org/material/iframe/id/dzcansfk/width/772/height/474/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/asb/false/sri/true/rc/false/ld/false/sdz/true/ctl/true"
width="772px" height="474px" style="border:0px;" allowfullscreen=""> </iframe>
</div>

Expand Down Expand Up @@ -1746,7 +1746,7 @@ <h4>1 Ordinary Differential Equations</h4>
</div>

<div>
<iframe scrolling="no" title="Overdamping" src="https://www.geogebra.org/material/iframe/id/wczhjd2h/width/772/height/474/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/asb/false/sri/true/rc/false/ld/false/sdz/false/ctl/true"
<iframe scrolling="no" title="L11: Overdamping" src="https://www.geogebra.org/material/iframe/id/wdfdrdyq/width/772/height/474/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/asb/false/sri/true/rc/false/ld/false/sdz/false/ctl/true"
width="772px" height="474px" style="border:0px;" allowfullscreen=""> </iframe>
</div>

Expand Down
15 changes: 8 additions & 7 deletions math1052/p1.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,18 @@ <h4>Mult. Calc. &amp; Ordinary Differential Equations</h4>
<a href="lecture-06.html" target="_blank">L6 Applications ODEs</a><br/>
<hr>

<a href="lecture-07.html" target="_blank">L7 Solns 1st-Or. ODEs</a><br/>
<a href="lecture-08.html" target="_blank">L8 2nd-Or. ODEs</a><br/>
<a href="lecture-09.html" target="_blank">L9 Hom. 2nd-Or. ODEs</a><br/>
<a href="lecture-07.html" target="_blank">L7 Solns 1stOrd ODEs</a><br/>
<a href="lecture-08.html" target="_blank">L8 2ndOrd ODEs</a><br/>
<a href="lecture-09.html" target="_blank">L9 Hom 2ndOrd ODEs</a><br/>

</td>
<td>
<a href="lecture-10.html" target="_blank">L10 Sim. Harm. motion 1</a><br/>
<a href="lecture-11.html" target="_blank">L11 Sim. Harm. motion 2</a><br/>
<a href="lecture-12.html" target="_blank">L12 Pendulum & <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Inhom. 2nd-Or. ODEs</a><br/>
<a href="lecture-10.html" target="_blank">L10 Simp Harm motion 1</a><br/>
<a href="lecture-11.html" target="_blank">L11 Simp Harm motion 2</a><br/>
<a href="lecture-12.html" target="_blank">L12 Pendulum & <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Inhom 2ndOrd ODEs</a><br/>
<hr>
<a href="lecture-13.html" target="_blank">L13 Inhom. 2nd-Or. ODEs</a><br/>
<a href="lecture-13.html" target="_blank">L13 Inhom 2ndOrd ODEs</a><br/>
<a href="lecture-14.html" target="_blank">L14 Energy principle</a><br/>

<hr>
Expand Down
15 changes: 15 additions & 0 deletions math1052/sketches/chapter-01/damped-oscillator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="p5.min.js"></script>

<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />

</head>
<body>
<main>
</main>
<script src="sketch.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions math1052/sketches/chapter-01/damped-oscillator/p5.min.js

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions math1052/sketches/chapter-01/damped-oscillator/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
@name Spring
@frame 710, 400
@description Click, drag, and release the horizontal bar to start the spring.
*/
// Spring drawing constants for top bar
let springHeight = 32,
left,
right,
maxHeight = 400,
minHeight = 0,
over = false,
move = false,
points = [],
maxPoints = 100;
diam = 60;

// Spring simulation constants
let M = 10.8, // Mass
K = 0.2, // Spring constant
D = 0.99, // Damping
R = 200; // Rest position

// Spring simulation letiables
let ps = R, // Position
vs = 0.0, // Velocity
as = 0, // Acceleration
f = 0; // Force

function setup() {
createCanvas(600, 400);
rectMode(CORNERS);
noStroke();
left = width / 2 + 100;
right = width / 2 - 100;

for (let i=0; i<maxPoints; i++) {
points[i] = ps;
}

}

function draw() {

background(150);
push();
translate(0,0)
springCurve(ps-50, 0, left);
line(left, ps-50, left, ps-32);
pop();
//cursor('default');
updateSpring();
drawSpring();
updateGraph();
drawGraph();

}

function drawSpring() {
// Draw base
//fill(0.2);
//let baseWidth = 0.5 * ps + -8;
//ellipse(width / 2 - baseWidth, ps + springHeight, 20);
//rect(width / 2 - baseWidth, ps + springHeight, width / 2 + baseWidth, height);

// Set color and draw top bar
if (over || move) {
fill(204, 179, 255);
} else {
fill(112, 50, 126);
}

stroke(200);
ellipse(left, ps, diam);
//rect(left, ps, right, ps + springHeight);
}

function updateSpring() {
// Update the spring position
if ( !move ) {
f = -K * ( ps - R ); // f=-ky
as = f / M; // Set the acceleration, f=ma == a=f/m
vs = D * (vs + as); // Set the velocity
ps = ps + vs; // Updated position
}

if (abs(vs) < 0.1) {
vs = 0.0;
}

// Test if mouse if over the top bar
let d = dist(left, ps, mouseX, mouseY);
if (d < diam/2) {
over = true;
cursor('grab');
} else {
over = false;
cursor('default');
}

// Set and constrain the position of top bar
if (move) {
ps = mouseY - springHeight / 2;
ps = constrain(ps, minHeight, maxHeight);
}
}

function updateGraph() {
points.shift();
points.push(ps);
}

function drawGraph() {
push();
stroke(0,0,250);
strokeWeight(2);
noFill();
beginShape();
for (let i=0; i<maxPoints; i++) {
vertex(i*3.7, points[i]);
}
endShape();
pop();
}

function springCurve(y0, y1, A){
//2sin(10 * 2π (t - y_1) / (y_0 - y_1)) + x(A2)
stroke(0);
strokeWeight(4);
noFill();
beginShape();
for(let k = -y1; k<y0; k=k+0.01){
let x = (20* sin( 10*PI*(k - y1) / (y0 - y1)) + A);
let y = k;
vertex(x, y);

}
endShape();

}

function mousePressed() {
if (over) {
move = true;
}
}

function mouseReleased() {
//cursor('default');
move = false;
}
9 changes: 9 additions & 0 deletions math1052/sketches/chapter-01/damped-oscillator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden
}
canvas {
display: block;
}

0 comments on commit 70f4003

Please sign in to comment.