Got Questions? Get Answers.
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:
Solving Ordinary Differential Equation with bvp4c Gives Error

Subject: Solving Ordinary Differential Equation with bvp4c Gives Error

From: Shen

Date: 29 Jun, 2010 21:05:12

Message: 1 of 1

I am trying to solve the first-order ordinary differential equation

dy/dx = -sqrt(2*M^2*(sqrt(1-2*y/M^2) - 1) + exp(y) - 1

with boundary conditions

y(0) = -2.84 + ln(M)
y(inf) = 0
y'(inf) = 0

When I use bvp4c to solve this, I get the error

"Unable to solve the collocation equations -- a singular Jacobian encountered"

What am I doing wrong? See here for my current code:

function mat4bvp
clear all; clc
M = 5;
% linspace(beginX,endX,#ofpoints)
solinit = bvpinit(linspace(0,1000,100),@mat4init,M);
sol = bvp4c(@mat4ode,@mat4bc,solinit);

xint = linspace(0,pi);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:))
% axis([0 pi -1 1.1])
title('Eigenfunction of Mathieu''s equation.')
xlabel('x')
ylabel('solution y')
% ------------------------------------------------------------
function dydx = mat4ode(x,y,M)
dydx = [ y(2)
         -sqrt(2*M^2*(sqrt(1-2*y(1)/M^2)-1)+exp(y(1))-1) ];
% 2nd order approximation:
% y(1)^2/(2*M^2) + 0.5*y(1)^2];
% ------------------------------------------------------------
function res = mat4bc(ya,yb,M)
% (1) is referring to original function
% (2) is referring to first derivative
% ya is at initial position a
% yb is at initial position b
res = [ yb(2)
         yb(1)
        ya(1)-(-2.84+log(M)) ];
% ------------------------------------------------------------
function yinit = mat4init(x)
yinit = [ -exp(-x) exp(-x)];

Tags for 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