MATLAB: How to plot a graph of a system of non-linear equations with a conditional function as a variable and initial conditions

conditional functiondifferential equationsnonlinearsystem

I need to plot a graph of z(t) (from t = 0 until t becomes periodic) in this system: dx/dt = y – 2*x + f(z) | dy/dt = x – 2*y + z | dz/dt = y – z. But the thing is f(z) = 34, if z > 1 | f(z) = -34, if z < -1 | f(z) = 34*z, if -1 < z < 1. The initial conditions are x(0) = 0 | y(0) = 0 | z(0) = 0.5 Unfortunately I can't seem to find a solution that applies f(z).

Best Answer

I would first define ‘f(z)’ as:
f = @(z) 34.*(z>1) - 34.*(z<-1);
then create a separate anonymous function for the system of differential equations, calling ‘f(z)’:
dx/dt = y - 2*x + f(z)
and the other two equations, using the appropriate vector elements for ‘x’, ‘y’, and ‘z’.
I already coded and ran this, and it is straightforward. Forum convention discourages our posting complete solutions, to homework assignments.
Give it a go. If you have problems, we will help.