My problem seems simple: U''(r)=-4*pi*r*n(r) where n(r) is a constant 1d-vector In addition I have the boundary conditions: U(0)=0 and U(r_max)=c, where c is a constant.
I've tried the following:
f = @(r,U) [ U(2); -4*pi.*r.*n];
g = @(ya,yb) [ya(1); yb(1)-c];
solinit=bvpinit(linspace(0,r_max,10),[0 0]);
sol = bvp4c(f,g,solinit);
In case n is just a number it works... For n being a vector it doesn't and i get the error:
Error using vertcat Dimensions of matrices being concatenated are not consistent.
Is there any way to include vectors in my function definition?
Thanks in advance.

 채택된 답변

Torsten
Torsten 2016년 8월 25일

0 개 추천

function main
rinter = ...;
ninter = ...;
c= ...;
g = @(ya,yb) [ya(1); yb(1)-c];
solinit=bvpinit(linspace(0,r_max,10),[0 0]);
sol = bvp4c(@(r,U)f(r,U,rinter,ninter),g,solinit);
function dUdr = f(r,U,rinter,ninter)
nr = interp1(rinter,ninter,r);
dUdr = zeros(2,1);
dUdr(1) = U(2);
dUdr(2) = -4*pi*r*nr;
Best wishes
Torsten.

댓글 수: 2

Thanks a lot. you made my day
Hi there, I have tried running the solution code, but a singular jacobian occurs for the choice of mesh. I think any mesh that has points between 0 and 1 will return a singular jacobian. Any ways to get around this? Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2016년 8월 25일

댓글:

2020년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by