Info

This question is closed. Reopen it to edit or answer.

How can I control an error caused by a singular jacobian in a function?

1 view (last 30 days)
Dear all
My code is simple.
After deciding the values of c and d utilizing a 'for-loop', I would like to solve a first order boundary value problem using 'bvp4c', a built-in toll in MATLAB, within c ≤ x ≤ d. The goal is to check all the possible values of c and d and to discover the value of c and d to satisfy the first order boudary value problem.
My problem is that the for-loop does not continue because 'a singuar jacobian' is encountered when RD(c,d)is executed (I guess that bvp4c does not operate when the boundary conditions are not satisfied). How can I continue the for-loop until I find the values of c and d satisfying the boundary conditions?
The other is that I want to save all figures generated excuting a for-loop. But, I could not find any way to change the figure name at saveas(h, 'ODE','jpg'). This could be done if I add the number to the figure name.
If you give me any hint, I will be thankful to you.
k = 0 ;
m = 1 ;
a = 0 ;
b = 2*pi ;
n = 5 ;
del = (b-a)/n ;
for i = a : del : b
c = a + del*k ;
k = k + 1 ;
for j = c : del : b
d = c + del*m ;
RD(c,d) ;
m = m + 1 ;
end
end
function sol = RD(m,n)
solinit = bvpinit(linspace(m,n,15),0,-10) ;
sol = bvp4c(@ode,@bcs,solinit) ;
h = figure('visible','off') ;
plot(sol.x, sol.y(1,:)) ;
saveas(h, 'ODE','jpg') ;
function dydx = ode(x, y, A)
s1 = 2*3^(1/2)*cos(y)^2 ;
s2 = 3^(1/2)*cos(y)^2 ;
s3 = -3^(1/2)*cos(y)^2 ;
ds1dy = 4*3^(1/2)*sin(2*y)*cos(y)^2 ;
dydx = -(3*cos(2*y) + sin(2*y)*cot(x))*s1 - s2 + s3 + A ;
function res = bcs(ya, yb, A)
res = [ ya + pi/4 ; yb - pi/4 ] ;

Answers (0)

Community Treasure Hunt

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

Start Hunting!