Solving ODE two sets of initial conditions

1 view (last 30 days)
moonman1
moonman1 on 5 Nov 2015
Commented: Star Strider on 5 Nov 2015
I have to solve the equation yp = [y(2);(-(z*y(2)+w*y(1)+beta*y(2)^3+n*y(1)^3))]; and display the results in a phase plot. How do I include initial conditions for both the displacement and the velocity? Here is my code:
function [t,y] = call_trial1()
tspan = [0 5]; % set time interval
y0 = [-1;1]; % set initial condition
[t,y] = ode15s( @trial1 ,tspan ,y0);
plot(t,y)
xlabel('Structural Displacement(m)')
ylabel('Structural Velocity(m/s)')
grid on
disp([t,y]) % displays t and y(t)
function yp = trial1 (t,y)
m=1.2; c=4; k=1600;
cf=-8; kf=100; beta=20; n=-2.5;
z=(cf-c)/m; w=(kf-k)/m;
yp = [y(2);(-(z*y(2)+w*y(1)+beta*y(2)^3+n*y(1)^3))];
end
end

Answers (1)

Star Strider
Star Strider on 5 Nov 2015
I may be missing something, but it seems you already have:
y0 = [-1;1]; % set initial condition
  5 Comments
moonman1
moonman1 on 5 Nov 2015
this is the equation i want to model. what is the best way to write it in matlab

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!