Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Using if statement in BVP4C

Subject: Using if statement in BVP4C

From: Sonny

Date: 29 Jul, 2014 22:13:10

Message: 1 of 1

I am trying to solve a boundary value problem, but where the ODE have a different constant added to the ODE if x<0 and one when x>0. If it possible to use and IF statement in the odefunc(x,y)??? My code is as follows

function dydx = odefunc(x,y)

%constant defined in problem
a = .9;
sig = 2;
h = 2;
c = 3;
p = 1;
g = 2;

    y = [y(1);y(2)];
    A = [0 1; 2*a/(sig^2) 2/(sig^2)*((g)/g+1)^(g+1)*(1/(y(1)+c))^(g+1)]; %The Diff eq
    constant_xneg = [ 0; -(2/sig^2)*(p-a*c)];%The negative case
    constant_xpos = [0;(2/sig^2)*(h+a*c)]; %The positive case
    
    if x>0
       dydx = A*y + constant_xpos;
    elseif x<0
       dydx = A*y + constant_xneg;
    else
        dydx = A*y;
    end

end

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us