I have a query to ask in matlab which i hope you can help with. I have some 50 images which i want to stack along the Z direction at a fixed interval between the images/slices i.e. images are parallel to X-Y plane. After stacking I want to develop a 3D image by using some kind of interpolation between the slices. Is this possible to do in matlab??. If possible can you shed some light on what lines should I proceed??
I try not to solve a problem numerically until I have a pretty good idea what the answer should look like. The best approach is to work out some kind of approximate analytical solution. Then this can be used as an initial guess for the numerical solution.
I knew the analytical solution for my problem, so it was pretty easy to formulate a rough guess. Also, this is a linear equation so the guess is relatively unimportant. Guesses are much more important for nonlinear equations.
I'll repeat, if you are going to solve a problem numerically, you should already know what the solution looks like. Use approximations to allow for analytical solutions of a simplified problem. Then you can use this approximation for the guess.
One more suggestion. The first time you use a tool like bvp4c, test it on a problem for which you know the exact solution. Then you can be sure you're using the tool correctly. Then you can move on to solve harder problems for which you don't have an analytical solution.
It could be you need a better initial guess. It also might be a problem with the equations themselves. I'd have to see the code to be sure. You can send me the code if you want me to look at it. Send to blanchard "at" engr.wisc.edu
I typed your exact script in and it didn't work. says there is an error, "Error in ==> bvp5 at 4 sol=bvp4c(@bvp5ode,@bvp5bc,solinit); " and "??? Error using ==> times Matrix dimensions must agree"
I'm guessing I have to rename a file or something syntax like. Does anyone know whats going on here?
Thanks for the video. Could you tell me how can I find the initial conditions like y(0)=0 and y'(pi/2)=1 for example for a given ODE or system of ODEs? I have read that we can do so by using Jacobian matrix ,but I don't know what to look for exactly. The initial conditions should be prescribed such that the ODE becomes stable i.e the real parts of the eigenvalues be negative.
You don't have to guess y(0), though there are algorithms that work that way. You can directly prescribe the derivative at either boundary. This is described in the video above. Go to about the 7:37 mark and watch until the end. That should help. Drop me a note if you still have questions.
hi, this is a really excellent video ya put up, very well explained!! im using matlab to solve a 2nd order BVP at the mo, however my system of first order ode's have non constant coefficients dependant on my independant variable u. is it just a matter of defining the coeffs and multiplying them by my y(1) and y(2) in my ode file before i execute the script? i seem to be getting errors relating back to my ode file. my bc's consist of y and y' at one given point. any insight wud be great, thanks
bvp4c will handle nonlinear equations. If you search the web for "MATLAB Central Tutorial BVP4C" you will find a zip file put together by Kierzenka. The pdf in that zip file describes a solution for a nonlinear equation.
Hi jake, thanks alot for your prompt response. my equation is actually linear in y, its just the coefficients of y, y' and y" are dependant on my independant variable u. i've since looked at, and printed off (paper is so much easier on the eyes) that tutorial by Kierzenka, thanks alot for suggesting it. they do quite a few examples that mirror my own problem to an extent.. i imagine i'll have the code working pretty soon. thanks again!!
Very nice explanations on solving boundary value problems! THANKS FOR THAT!
But when trying to compile the code in Matlab (R2008a) I realized that there are semicolons (;) missing for the vectors dydx and res in the functions describing the differential equation and the boundary conditions, respectively. Matlab needs vertical vectors to handle the ODE. Or am I wrong? At least it worked out fine when adding the semicolons.
Hi Mr.Jakeblanchard,
I have a query to ask in matlab which i hope you can help with. I have some 50 images which i want to stack along the Z direction at a fixed interval between the images/slices i.e. images are parallel to X-Y plane. After stacking I want to develop a 3D image by using some kind of interpolation between the slices. Is this possible to do in matlab??. If possible can you shed some light on what lines should I proceed??
Thankyou for your time!!!
MsChano87 1 month ago
@MsChano87
I have no idea if this is possible. Sorry.
jakeblanchard 1 month ago
Thanks for the very useful video. I can't understand how can I find the guess of my bvp.. could you help me? and how did you choose yours?
fgiuglia 8 months ago
@fgiuglia
I try not to solve a problem numerically until I have a pretty good idea what the answer should look like. The best approach is to work out some kind of approximate analytical solution. Then this can be used as an initial guess for the numerical solution.
jakeblanchard 8 months ago
@jakeblanchard
Thank you very much. Sorry if I am not smart, but what is the link with the constants in the initial guess and your solution?
fgiuglia 8 months ago
@fgiuglia
I knew the analytical solution for my problem, so it was pretty easy to formulate a rough guess. Also, this is a linear equation so the guess is relatively unimportant. Guesses are much more important for nonlinear equations.
I'll repeat, if you are going to solve a problem numerically, you should already know what the solution looks like. Use approximations to allow for analytical solutions of a simplified problem. Then you can use this approximation for the guess.
jakeblanchard 8 months ago
@jakeblanchard
One more suggestion. The first time you use a tool like bvp4c, test it on a problem for which you know the exact solution. Then you can be sure you're using the tool correctly. Then you can move on to solve harder problems for which you don't have an analytical solution.
jakeblanchard 8 months ago
@jakeblanchard thank you, I will try to manage it!
fgiuglia 8 months ago
Thanks for the very useful video. I can't understand how can I find the guess of my bvp.. could you help me?
fgiuglia 8 months ago
I got an error saying:
??? Error using ==> bvp4c
Unable to solve the collocation equations -- a singular Jacobian encountered.
how do i solve this?
uoweme5grand 8 months ago
@uoweme5grand
It could be you need a better initial guess. It also might be a problem with the equations themselves. I'd have to see the code to be sure. You can send me the code if you want me to look at it. Send to blanchard "at" engr.wisc.edu
jakeblanchard 8 months ago
I typed your exact script in and it didn't work. says there is an error, "Error in ==> bvp5 at 4 sol=bvp4c(@bvp5ode,@bvp5bc,solinit); " and "??? Error using ==> times Matrix dimensions must agree"
I'm guessing I have to rename a file or something syntax like. Does anyone know whats going on here?
hellsangelsdeath 10 months ago
@hellsangelsdeath
You can download some working files from
blanchard "dot" ep "dot" wisc "dot" edu/PublicMatlab/#BVP
jakeblanchard 10 months ago
Just curious, how does changing the initial mesh to having just 5 points affect your final answer?
brynntheoose 10 months ago
@brynntheoose
As you reduce the size of the initial mesh you will increase the error.
jakeblanchard 10 months ago
This was extremely helpful, especially the section on defining the boundary conditions as a vector, thank you!
brynntheoose 10 months ago
Thanks for the video. Could you tell me how can I find the initial conditions like y(0)=0 and y'(pi/2)=1 for example for a given ODE or system of ODEs? I have read that we can do so by using Jacobian matrix ,but I don't know what to look for exactly. The initial conditions should be prescribed such that the ODE becomes stable i.e the real parts of the eigenvalues be negative.
supernova1387 1 year ago
@supernova1387
No, I've never seen what you describe. I've only done problems where the boundary conditions are prescribed.
jakeblanchard 1 year ago
Great Video!!! Thank you so much.
Your explanation is very clear.
Could you give me a suggestion, please.
If my boundary condition is in form y'... for example ... y'(0) = 0 and y'(10) = 0.
How I can solve it in MATLAB?
I try to guess initial point of y(0), but it seems wrong,
Thank you in advance ;)
jejeejajar 1 year ago
@jejeejajar
You don't have to guess y(0), though there are algorithms that work that way. You can directly prescribe the derivative at either boundary. This is described in the video above. Go to about the 7:37 mark and watch until the end. That should help. Drop me a note if you still have questions.
jakeblanchard 1 year ago
@jakeblanchard
Thank you so much for your response.
I'll try to solve it.
I doubt why I missed your video, it's wonderful ;)
jejeejajar 1 year ago
thx man :)
666luster666 1 year ago
THANK YOU SO MUCH. It was very wonderfully explained. Felt so easy about BVPs. Hats off :)
sreeeeee777 1 year ago
hi, this is a really excellent video ya put up, very well explained!! im using matlab to solve a 2nd order BVP at the mo, however my system of first order ode's have non constant coefficients dependant on my independant variable u. is it just a matter of defining the coeffs and multiplying them by my y(1) and y(2) in my ode file before i execute the script? i seem to be getting errors relating back to my ode file. my bc's consist of y and y' at one given point. any insight wud be great, thanks
tasslebear82 2 years ago
bvp4c will handle nonlinear equations. If you search the web for "MATLAB Central Tutorial BVP4C" you will find a zip file put together by Kierzenka. The pdf in that zip file describes a solution for a nonlinear equation.
jakeblanchard 2 years ago
Hi jake, thanks alot for your prompt response. my equation is actually linear in y, its just the coefficients of y, y' and y" are dependant on my independant variable u. i've since looked at, and printed off (paper is so much easier on the eyes) that tutorial by Kierzenka, thanks alot for suggesting it. they do quite a few examples that mirror my own problem to an extent.. i imagine i'll have the code working pretty soon. thanks again!!
tasslebear82 2 years ago
hi, many thanks for this video and relevant others. it makes my life much easier. really appreciate it.
karst9900 2 years ago
Very nice explanations on solving boundary value problems! THANKS FOR THAT!
But when trying to compile the code in Matlab (R2008a) I realized that there are semicolons (;) missing for the vectors dydx and res in the functions describing the differential equation and the boundary conditions, respectively. Matlab needs vertical vectors to handle the ODE. Or am I wrong? At least it worked out fine when adding the semicolons.
ciwstevie 3 years ago
Good point. You are correct. There is a typo in the scripts shown in this video. Specifically, the boundary condition function should be written as
function res=bvp4bc(ya,yb)
res=[ya(1)-1; yb(1)];
jakeblanchard 3 years ago