Question

Using Octave to solve (preferably with solving the differential equations and go through the process)

1. A harmonic oscillator obeys the equation dx dt dt which can be written as a set of coupled first order differential equati

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given the equation

\frac{dx}{dt}=v

And

\frac{dv}{dt}=- \gamma v-\frac{k}{m}x........................(i)

Let

x_1=x,x_2= \frac{dx}{dt}

It follows x_2= \dot x_1

Therefore equation (i) can be written as

\dot x_2=- \gamma x_2-\frac{k}{m}x_1

For m=k=1 , the above equation reduces to

\dot x_2=- \gamma x_2-x_1

given the initial conditions x(0)=1, v(0)=0

Now we write a function file [ & save the file with the name 'odeshm' ]for the above equation, taking the value \gamma =1 . [ We can modify \gamma later for different values]

%%%%MATLAB CODE%%%%%%%

function f = odeshm(t,x)

gamm1=1;

f = zeros(2,1);
f(1) = x(2);
f(2) = -gamma*x(1)-x(2);

%%%%%% NOW IN SEPARATE SCRIPT FILE WRITE THE FOLLOWING CODE AND RUN IT%%%%%

clear; close all;
tspan = 0:0.05:10; % time span
x0 = [1;0]; % initial conditions
[t,x] = ode23('odeshm',tspan,x0);
plot(t,x(:,1));
xlabel('Time [s]')
ylabel('Displacement [m]')
title(' gamma =1');

gamma =1 1.2 0.8 0.6 0.4 0.2 -0.2 0 12345 6 78910 Time [s]gammaO 1.8 1.4 드1.2 0.6 0.4 0.2 0 12345 6 78910 Time [s]gamma 2 0.8 0.6 는 04 0.2 -0.2 0.4 0 12345 6 78910 Time [s]gamma 4 0.5 0.5 0 12345 6 78910 Time [s]

Add a comment
Know the answer?
Add Answer to:
Using Octave to solve (preferably with solving the differential equations and go through the process) 1. A harmonic osc...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT