Вы находитесь на странице: 1из 4

To solve any differential equation numerically using

matlab Fist you must put your differential equation in

” matlab function form “


And call this function by the build-in function “ ode45

Example

Divide the equation into two differential equation by


introduce the new variables

Then

Now transforms the math equations above into


matlab function
let F=5
Open new m-file , write this function
function fdot = q8eng(x,f)
fdot(1)= f(2);
fdot(2)= (1/5)*(5 -4*f(1) -7*f(2));
fdot=[fdot(1) ; fdot(2)];
end

save it as q8eng.m

in the command window call your function

[x,y]=ode45(@q8eng ,[0:0.1:9],[0.1 1]);


ode45 command means “please Mr matlab solve the
differential equation located in q8eng function from
x=0 to 9 with 0.1 increament with the initial
conditions x_1=y=0.1 and x_2=y_dot=1

the output of the ode45 command are x and y


where x is a colum vector contains the domain
specified [0:0.1:9]
and y in a matrix contains two columns (colum one is
y and colum two is y_dot)
To plot the solution
plot(x,y(:,1))

As a check if the equation is for spring-mass-damper


system
the steady state response will be F/K=1.25 which is
clear from the diagram
Or simply you can shrink the q8eng function into
another(Name it any name ) one contains the ode45
commat ,
function lool

function fdot = q8eng(x,f)


fdot(1)= f(2);
fdot(2)= (1/5)*(5 -4*f(1) -7*f(2));
fdot=[fdot(1) ; fdot(2)];
end

[x,y]=ode45(@q8eng ,[0:0.1:9],[0.1 1]);


plot(x,y(:,1))
end

===========================

Вам также может понравиться