Force Amp. =50 N

Modal Freqs.

\f\sub{1} = \reg{}{fm1-value} \f\sub{2} = \reg{}{fm2-value}

Mass 2 / Mass 1

Spring 2 / Spring 1

Natural Freq. 2

\f\sub{0\sub{2}} = \reg{}{fn2-value}

Damper 2:\ratio{kg}{s}

Mass 1:4 kg

Spring 1:160 N/m

Natural Freq. 1:

\f\sub{0\sub{1}} = \reg{}{fn1-value}

Damper 1:\ratio{kg}{s}

Mark subsystem
natural freqs.

Plot phase
relative to

let init = false color.add("fd","var(--sharp-green)","var(--mid-green)") reg.osc.freq.handleGroup.firstChild.style.fill = color.fd reg.osc.freq.handleText.style.fontWeight = 900 reg.osc.freq.handleText.style.color = "black" color.add("fm","var(--sharp-purple)","var(--sharp-purple)") reg.fmCard.style.background = color.fm reg.fmCard.style.color = color.textInv color.add("m1",color.main) reg.m1Card.style.background = color.m1 reg.m1Card.style.color = color.textInv color.add("m2",color.second) reg.m2Card.style.background = color.m2 reg.m2Card.style.color = color.textInv const spaceWidth = this.width/4 const p1 = this.newPlot({ position: [ this.left+100+20, this.bottom+20 ], size: [spaceWidth, this.height-40], rangeX: [-3,3], rangeY: [-5,10], labelX: "", labelY: "Position [m]", gridX: false, tickArrayX: [], tickEndsX: false, tickArrayX: [-10], tickLabelFontSizeY: 30, tickLabelGapY: 10, labelFontSizeY: 40, labelGapY: 25, tickStepY: 1, }) const p2 = this.newPlot({ position: [ this.left + 100 + spaceWidth + 150, this.center-50], size: [this.width - spaceWidth - 100 - 150 - 20 ,this.height/2 - 40 ], rangeX: [0,2], rangeY: [0,5], labelX: "", labelY: "Amplitude [m]", tickStepX: 0.5, tickStepY: 1, labelFontSizeX: 40, labelFontSizeY: 40, }) const [p2x,p2y] = p2.position const [p2w,p2h] = p2.size p2.text({ text:"Steady-State Displacement Response", position:[p2x+p2w/2,p2y+p2h+20], anchor:[0.5,0], screen: true, clip: false, fontSize: 50, }) const p3 = this.newPlot({ position: [p2x,this.bottom+100], size: [p2w,p2h - 170], rangeX: [0,2], rangeY: [-pi*1.01,pi*1.01], labelX: "Driving Frequency [Hz]", labelY: "\\reg{Relative}{phase-type-lab} Phase [rad]", tickStepX: 0.5, tickArrayY: [0,{value:pi,label:"\\pi"},{value:pi/2,label:"\\frac{\\pi}{2}"},{value:-pi,label:"-\\pi"},{value:-pi/2,label:"\\frac{-\\pi}{2}"}], labelFontSizeX: 40, labelFontSizeY: 40, }) let ampM1, phaseM1, dispM1, ampM2, phaseM2, dispM2, fLength, fm1, fm2, dampRatio1, dampRatio2, fn1, fn2 const m1Value = 4 const s1Value = 159 const posM1 = 0 const posS1 = -5 const posM2 = 5 const heightM = 1 const posS2 = posM1 + heightM const ampF = 50 reg.osc.onUpdate(t=>{ updatePosition() m1g.update() s1g.update() r1g.update() m2g.update() s2g.update() r2g.update() force.update() }) reg.freq.onUpdate(()=>updateAll()) reg.r1.onUpdate(()=>updateAll()) reg.m2.onUpdate(()=>updateAll()) reg.s2.onUpdate(()=>updateAll()) reg.r2.onUpdate(()=>updateAll()) reg.phaseType.onUpdate(v=>{ reg.phaseType.button.style.background = v?"":color.fd reg.phaseType.button.style.color = v?"":color.textInv frfPh1.classList.toggle("hidden",v) frfPh2.classList.toggle("hidden",v) frfPhDiff.classList.toggle("hidden",!v) reg.phaseTypeLab.update(!v?"":"Relative ") updateGroups() }) reg.subSystem.onUpdate(v=>{ f01.hide(!v) f02.update() f02.style.stroke = !v?color.highlight:color.second f02.style.color = !v?color.highlight:color.second }) function updateAll(){ updateResponse() updatePosition() updateGroups() } function updateGroups(){ m1g.update() s1g.update() r1g.update() m2g.update() s2g.update() r2g.update() force.update() frf.update() frfPh.update() freqMarks.update() } function updateResponse(){ const fT = frequency() fm1 = fT.mode[0]/pi2 fm2 = fT.mode[1]/pi2 fn1 = fT.nat[0]/pi2 fn2 = fT.nat[1]/pi2 reg.fm1Value.textContent = format(fm1,3,"Hz") reg.fm2Value.textContent = format(fm2,3,"Hz") reg.fn1Value.textContent = format(fn1,3,"Hz") reg.fn2Value.textContent = format(fn2,3,"Hz") const [A1,A2,ph1,ph2] = ampPhase(reg.freq.value) ampM1 = A1 ampM2 = A2 phaseM1 = ph1 phaseM2 = ph2 if(init){ s1Spr.style.strokeWidth = 5 s2Spr.style.strokeWidth = 1 + 4*reg.s2.ratio } } function updatePosition(){ const T = pi2*reg.freq.value*reg.osc.value fLength = cos(T) dispM1 = ampM1*cos(T - phaseM1) dispM2 = ampM2*cos(T - phaseM2) } updateResponse() updatePosition() function frequency(){ const r1 = reg.r1.value const m2 = reg.m2.value * m1Value const s2 = reg.s2.value * s1Value const r2 = reg.r2.value const A = (s1Value + s2)*m2 + m1Value*s2 const B = sqrt(A**2 - 4*m1Value*m2*s1Value*s2) const C = 2*m1Value*m2 const mode = [sqrt((A - B) / C), sqrt((A + B) / C)] const nat = [sqrt(s1Value/m1Value),sqrt(s2/m2)] return {mode,nat} } function ampPhase(f){ const r1 = reg.r1.value const m2 = reg.m2.value * m1Value const s2 = reg.s2.value * s1Value const r2 = reg.r2.value const w = pi2*f const w1 = sqrt(s1Value/m1Value) const w2 = sqrt(s2/m2) const B1 = r1/(2*m1Value) const B2 = r2/(2*m2) const a = w**4 - ( w1**2 + w2**2*( 1 + m2/m1Value ) + 4*B1*B2 )*w**2 + w1**2 * w2**2 const b = ( B1*w1*w2**2 + B2*w1**2 )*w - ( B1 + B2*( 1 + m2/m1Value ) )*w**3 const A1 = (ampF / s1Value) * w1**2 * hypot(w2**2 - w**2, 2*B2*w) / hypot(a, 2*b) const A2 = (ampF / s2) * w1**2 * hypot(w2**2, 2*B2*w) / hypot(a, 2*b) const phD = atan(2*b, a) const ph1 = phD - atan(2*B2*w, w2**2 - w**2) const ph2 = phD - atan(2*B2*w, w2**2) return [A1, A2, wrap(ph1), wrap(ph2)] } const m1g = p1.group("m1") p1.line({ x:()=>[0,2.15], y:()=>[posM1 + dispM1,posM1 + dispM1], group: m1g, strokeLinecap: "square", strokeWidth: 2, }) p1.rect({ position: ()=>[0,posM1 + dispM1], size: ()=>[4,heightM], corner: 10, group: m1g, }) p1.text({ position: ()=>[0,posM1 + dispM1], text: "m\\sub{1}", group: m1g, color: color.textInv }) const m2g = p1.group("m2") p1.line({ x:()=>[0,2.15], y:()=>[posM2 + dispM2,posM2 + dispM2], group: m2g, stroke: color.second, strokeLinecap: "square", strokeWidth: 2, }) p1.rect({ position: ()=>[0,posM2 + dispM2], size: ()=>[2 + 2*reg.m2.ratio,heightM], corner: 10, fill: color.second, group: m2g, }) p1.text({ position: ()=>[0,posM2 + dispM2], text: "m\\sub{2}", group: m2g, color: color.textInv }) const s1g = p1.group("s1") const s1Spr = p1.spring({ start:()=>[-1,posS1], end:()=>[-1,posM1 - heightM/2 + dispM1], coils:6, diameter:1.5, group:s1g, stroke:color.neutral }) p1.rect({ position: ()=>[-2.75,(posS1 + posM1 + dispM1)/2], size: ()=>[p1.fromXsize(50),p1.fromYsize(50)], anchor: [0,0.5], corner: 10, group: s1g, opacity:0.25, stroke:color.neutral, }) p1.text({ position: ()=>[-2.75 + p1.fromXsize(50)/2,(-5 + posM1 + dispM1)/2], text: "s\\sub{1}", group: s1g, }) const s2g = p1.group("s2") const s2Spr = p1.spring({ start:()=>[-1,posM1 + heightM/2 + dispM1], end:()=>[-1,posM2 + dispM2 - heightM/2], coils:6, diameter:1.5, group:s2g, stroke:color.neutral }) p1.rect({ position: ()=>[-2.75,((posM1 + heightM/2 + dispM1) + (posM2 + dispM2 - heightM/2))/2], size: ()=>[p1.fromXsize(50),p1.fromYsize(50)], anchor: [0,0.5], corner: 10, group: s2g, opacity:0.25, stroke:color.neutral, }) p1.text({ position: ()=>[-2.75 + p1.fromXsize(50)/2,((posM1 + heightM/2 + dispM1) + (posM2 + dispM2 - heightM/2))/2], text: "s\\sub{2}", group: s2g, }) const r1g = p1.group("r1") p1.damper({ start:()=>[1,posS1], end:()=>[1,posM1 - heightM/2 + dispM1], gap:()=>(1-reg.r1.ratio**0.5), atRatio:()=>0.5, diameter:1, group:r1g, stroke:color.neutral }) p1.rect({ position: ()=>[2,(posS1 + posM1)*(4/5)], size: ()=>[p1.fromXsize(50),p1.fromYsize(50)], anchor: [0,0.5], corner: 10, group: r1g, opacity:0.25, stroke:color.neutral, }) p1.text({ position: ()=>[2 + p1.fromXsize(50)/2,(posS1 + posM1)*(4/5)], text: "r\\sub{1}", group: r1g, }) const r2g = p1.group("r2") p1.damper({ start:()=>[1,posM1 + heightM/2 + dispM1], end:()=>[1,posM2 + dispM2 - heightM/2], gap:()=>(1-reg.r2.ratio**0.5), atRatio:()=>0.5, diameter:1, group:r2g, stroke:color.neutral }) p1.rect({ position: ()=>[1.5,((posM1 + heightM/2 + dispM1) + (posM2 + dispM2 - heightM/2))/2], size: ()=>[p1.fromXsize(50),p1.fromYsize(50)], anchor: [0,0.5], corner: 10, group: r2g, opacity:0.25, stroke:color.neutral, }) p1.text({ position: ()=>[1.5 + p1.fromXsize(50)/2,((posM1 + heightM/2 + dispM1) + (posM2 + dispM2 - heightM/2))/2], text: "r\\sub{2}", group: r2g, }) const frf = p2.group("frf") p2.plotFn({ y: f => { const [A1,A2,ph1,ph2] = ampPhase(f) return A2 }, group: frf, stroke: color.second, }) p2.plotFn({ y: f => { const [A1,A2,ph1,ph2] = ampPhase(f) return A1 }, group: frf, }) const frfPh = p3.group("frfPh") const frfPh2 = p3.plotFn({ y: f => { const [A1,A2,ph1,ph2] = ampPhase(f) return ph2 }, group: frfPh, stroke: color.second, }) const frfPh1 = p3.plotFn({ y: f => { const [A1,A2,ph1,ph2] = ampPhase(f) return ph1 }, group: frfPh, }) const frfPhDiff = p3.plotFn({ y: f => { const [A1,A2,ph1,ph2] = ampPhase(f) return ph2 - ph1 }, group: frfPh, }) frfPh1.classList.add("hidden") frfPh2.classList.add("hidden") const freqMarks = p3.group("freqMarks") p2.line({ x: ()=>[fm1,fm1], y: ()=>[p2.fromY(p3.toY(p3.y.min)),p2.y.max], group: freqMarks, strokeWidth: 2, stroke: color.fm, clip: false, dash: "10 10" }) p2.line({ x: ()=>[fm2,fm2], y: ()=>[p2.fromY(p3.toY(p3.y.min)),p2.y.max], group: freqMarks, strokeWidth: 2, clip: false, dash: "10 10", stroke: color.fm, }) const f01 = p2.group(freqMarks) f01.hide() const f02 = p2.group(freqMarks) f02.style.color = color.highlight f02.style.stroke = color.highlight p2.line({ x: ()=>[fn1,fn1], y: ()=>[p2.fromY(p3.toY(p3.y.min)),p2.y.max], group: f01, strokeWidth: 2, clip: false, dash: "20 5", stroke: color.main }) p2.line({ x: ()=>[fn2,fn2], y: ()=>[p2.fromY(p3.toY(p3.y.min)),p2.y.max], group: f02, strokeWidth: 2, clip: false, dash: "20 5", stroke: "inherit" }) p2.text({ clip: false, text: "\\f\\sub{1}", color: color.fm, group: freqMarks, position: ()=>[fm1,4.5], opaque: true, }) p2.text({ clip: false, text: "\\f\\sub{2}", color: color.fm, group: freqMarks, position: ()=>[fm2,4.5], opaque: true, }) p2.text({ clip: false, text: "\\f\\sub{0\\sub{1}}", color: color.main, group: f01, position: ()=>[fn1,3.5], opaque: true, }) p2.text({ clip: false, text: ()=>reg.subSystem.value?"\\f\\sub{0\\sub{2}}":"\\f\\sub{absorb}", color: "inherit", group: f02, position: ()=>[fn2,3.5], opaque: true, }) const force = p1.group("force") p1.arrow({ start:()=>[2.1,posM1 + dispM1], end:()=>[2.1,posM1 + dispM1 + fLength], size:()=>[0.2,0.3], fill:color.fd, stroke:color.fd, strokeWidth:5, group: force, }) p2.line({ x: ()=>[reg.freq.value,reg.freq.value], y: ()=>[p2.fromY(p3.toY(p3.y.min)),p2.y.max], stroke: color.fd, group: freqMarks, strokeWidth: 2, clip: false, }) p2.circle({ position: ()=>[reg.freq.value,ampM2], radius: 4, fill: color.fd, stroke: color.textInv, strokeWidth:1.5, group: freqMarks, }) p2.circle({ position: ()=>[reg.freq.value,ampM1], radius: 6, fill: color.fd, stroke: color.textInv, strokeWidth:1.5, group: freqMarks, }) p3.circle({ position: ()=>[reg.freq.value,!reg.phaseType.value?phaseM2:-10], radius: 4, fill: color.fd, stroke: color.textInv, strokeWidth:2, group: freqMarks, }) p3.circle({ position: ()=>[reg.freq.value,!reg.phaseType.value?phaseM1:phaseM2-phaseM1], radius: 6, fill: color.fd, stroke: color.textInv, strokeWidth:1.5, group: freqMarks, }) p2.text({ clip: false, text: "\\f\\sub{drive}", color: color.fd, group: freqMarks, position: ()=>[reg.freq.value,2.5], opaque: true, }) init = true