MATLAB Answers

Not spotting where/how index exceeds number of array elements

5 views (last 30 days)
Brian Taff
Brian Taff on 13 Dec 2019
Commented: Brian Taff on 21 Dec 2019
I'm trying to solve a Navier-Stokes setup in a cylindrical coordinate system and am bumping up against an array indexing challenge. Any help folks might be able to offer to straighten matters out would be most appreciated. I'm including my live editor content below.

  0 Comments

Sign in to comment.

Accepted Answer

Vladimir Sovkov
Vladimir Sovkov on 14 Dec 2019
Is this what you want? Live script vesion is attached.
xmesh = linspace(0.01,0.05,5);
solinit = bvpinit(xmesh, @guess);
sol = bvp4c(@bvpfcn, @bcfcn, solinit);
plot(sol.x, sol.y, '-o')
function bound = bcfcn(ua,ub)
bound = [ua(1)-0.1, ub(1)];
end
function g = guess(r)
g = [1*(0.05-r)/(0.05-0.01), -1/(0.05-0.01)];
end
function dudr = bvpfcn(r,u)
dudr = [u(2), u(2)./r];
end

  4 Comments

Show 1 older comment
Brian Taff
Brian Taff on 19 Dec 2019
Many thanks, Vladimir. Based on your feedback I am up and running. To provide an update for any subsequent readers, I'm attaching the revised and corrected content.
Yes, two issues:
  1. An oversight on my part of the ./ operator and
  2. A late realization that running of live .mlx scripts only executes the "section" of the report where you are located without some added caretaking.
Vladimir Sovkov
Vladimir Sovkov on 20 Dec 2019
No prob.
I do not understand why you replace your initial equation by . It seems to me that must have been with the "plus" sign, and, consequently, dudr = [u(2), u(2)./r] in the program, isn't it? Otherwise, you are solving the equation .
Brian Taff
Brian Taff on 21 Dec 2019
You are correct, I had mistyped the original equation in the live editor's documentation. It should have been stated as u'' + u'/r = 0.
The downstream function calls do, in fact, solve this equation and the results were as intended.

Sign in to comment.

More Answers (0)

Sign in to answer this question.