No video

MATLAB Help - Multi-Dimensional Newton Rapshon

  Рет қаралды 28,405

Monte Carlos

Monte Carlos

Күн бұрын

How to use Newton Raphson for more than just one dimension.
Things to look out for in N-Dimensional Newton-Raphson
1.) Stationary points - gradient is 1D or det(jacobian) = 0
2.) Poor initial conditions - Try a few different initial conditions to prevent local minima.
3.) Overshoot - Change that alfa parameter to make sure you don't blow up
4.) There are many other problems but those are the most important.

Пікірлер: 60
@88ahh
@88ahh 9 жыл бұрын
Thank you very much man. I watched it 3 times ;)
@denizdurer6295
@denizdurer6295 3 жыл бұрын
I have got two function fval(1,1)=r2cos(q)+r3cos(x)-r4cos(y)-r1; fval(2,1)=r2sin(q)+r3sin(x)-r4sin(y); r values are given and q is at [0,2pi] and delta q is 2.5 degrees. I have to plot q versus x and q versus y graph. How can I do that??
@ManhaNAsad
@ManhaNAsad 8 жыл бұрын
Dear CM, It has been a pleasure watching your tutorials. With your kind help, I have started learning much more, I expected to do by my own. Could you please find some time to make a tutorials on Gauss Seidel/Newton Raphson for a system of form AX=B? Thanks
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
+zhk I've never done this type of system using Newton-Raphson mainly because the system is linear. Typically AX=B is solved the easiest using row reduction such as using rref(). kzbin.info/www/bejne/oJbCcmqgpMyrl7M NR is typically reserved for non-linear systems.
@ManhaNAsad
@ManhaNAsad 8 жыл бұрын
+Carlos Montalvo Thanks dear for your prompt reply. In the back of my head, I was thinking to learn to use NR while solving a PDE. For this purpose, I thought that AX=B, will be a good starting point. How stupid of me, as you have mentioned correctly, the application of NR is to solve nonlinear systems. I have watched the rref() video many times and for the first time, I learned how to code rref manually, Thanks to you. By the way, you can use this example (x^2+x*y=10, y+3*x*y^2=57 with the solution x=2 and y=3), if you are plannning to do a tutorials on NR for a nonlinear system?
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
+zhk Ok that's a standard non-linear system with two equations. The video here is just 1 equation with two unknowns. I'm actually working on a video right now using NR and Broyden's method that I should be finished with sometime this week. If you can wait a few days I can solve that problem you just posted. You subscribed to my channel so you should get an email about it once I post it.
@ManhaNAsad
@ManhaNAsad 8 жыл бұрын
Sure. I can wait. Thanks
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
I realize I took 5 months to get to this but here is a video on Broyden's method kzbin.info/www/bejne/l6Clomxrf7aep68
@saddamhussainsoomro2810
@saddamhussainsoomro2810 4 жыл бұрын
why you use xx or yy and zz, why not single x y or z??? why you show some extra skills here to confuse the new learners, please make it simple and straight forward, and how to solve n equations with n variables? Thanks and please dont mind sir
@CarlosMontalvo251
@CarlosMontalvo251 4 жыл бұрын
Variable names can be whatever you want. Single x,y, and z is totally valid but I use it to denote single dimensional vectors. xx,yy, and zz are matrices. If you read the documentation on meshgrid www.mathworks.com/help/matlab/ref/meshgrid.html they use capital letters to denote matrices but I don't like having to deal with case sensitive variables. So it's more of a personal preference. This youtube video is straightforward and has helped many people. It is by no means a "new learner" video. You need to be familiar with : plotting in 3D - kzbin.info/www/bejne/foSroaJtft1mncU meshing - kzbin.info/www/bejne/hmeZhKOsn5l7f68 and of course single dimensional newton raphson - kzbin.info/www/bejne/iZzLmJSNndOYZq8 Good luck in your studies. As for solving n equations and n unknowns, it depends on if the equations are nonlinear or not. If they are linear you just need to solve a standard linear set of equations Ax = b where the solution is just A\b If the equations are nonlinear then you have to use an optimization technique. NR is a good start.
@saddamhussainsoomro2810
@saddamhussainsoomro2810 4 жыл бұрын
@@CarlosMontalvo251 Thanks sir
@harsharajendran41088
@harsharajendran41088 3 жыл бұрын
Hello, I have a quadratic function to solve. with 4 variables and there are 4 equations. How do I iterate in matlab?
@CarlosMontalvo251
@CarlosMontalvo251 3 жыл бұрын
This is a tough problem. The solution I presented above is with 1 equation and 2 unknowns. That is z = f(x,y) and you're trying to solve where z =0. Your situations is 4 independent function fn(x,y,z,y) = 0 where fn has 4 function f1,f2,f3,f4. Unfortunately the only way I have come close to solutions like that is where I minimize a scalar cost function. In your case I would set z = f1^2 + f2^2 + f3^2 + f4^2 and then find x,y,z,t that minimizes z or in this case finds where z = 0.
@raghundon
@raghundon 8 жыл бұрын
Thank you for the presentation. How to solve a set of transcendental equations using newton raphson? Can you please make a video for that?
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
Can you give me an example of a set of transcendental equations?
@raghundon
@raghundon 8 жыл бұрын
Something like this - cos x1 + cos x2 + cosx 3 = 3M cos5 x1 + cos5 x2 + cos5x 3 = 0 cos7 x1 + cos7 x2 + cos7x 3 = 0 M ranges from 0 to 1.
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
Are those three separate equations? Or do you want the minimum of all three simultaneous equations? Your second and third equations don't make sense. What is cos5 x2? Is that cos(5*x2) where x2 is a variable? Or is it cos(5)*x2? Also, functions like sine and cosine are cyclic and thus have multiple solutions. Are you sure this is what you want?
@raghundon
@raghundon 8 жыл бұрын
Thank you for the reply, sorry for the poor typing. This should make it clear - cos a + cos b + cos c = 3M cos 5a + cos 5b + cos 5c = 0 cos 7a + cos 7b + cos 7c = 0 M varies b/w 0 to 1. a, b and c are variables. It should be solved simultaneously. Yes, u r right they result in multiple solutions. I want exactly that. The resultant contours aren't continuous either. This makes the programming challenging Thank you!
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
Ok yea so basically you have an equation of the form f(x) = 0 where f is a vector function and x is a vector as well. It's almost the same as the video, the only different is that f is now a vector. Let me think about it for a bit and get back to you.
@mehmetkaraaslan1649
@mehmetkaraaslan1649 5 жыл бұрын
Do you have any video for modified Newton Raphson method.?
@CarlosMontalvo251
@CarlosMontalvo251 5 жыл бұрын
Do you mean like secant method. kzbin.info/www/bejne/nGici3WMmJiHY68
@abdullahomair2811
@abdullahomair2811 8 жыл бұрын
Hey man, you are the one. Could we have the code . Thanks.
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
+Abdullah Omair function newton2D() clc close all x = -5:0.1:5; y = -5:0.1:5; [xx,yy] = meshgrid(x,y); zz = f(xx,yy); mesh(xx,yy,zz) %%% f = 0 hold on r0 = [-1;1]; %%initial guess on x is 10 and my initial guess on y is 10 alfa = 0.1; while abs(f(r0(1),r0(2))) > 1e-5 r0 = r0 - alfa*f(r0(1),r0(2))./fprime(r0(1),r0(2)); plot3(r0(1),r0(2),f(r0(1),r0(2)),'rs','MarkerSize',20) end r0 f(r0(1),r0(2)) theta = linspace(0,2*pi,100); r = 5; xc = r*cos(theta); yc = r*sin(theta); %plot3(xc,yc,0*xc,'r-','LineWidth',5) hold on %%%Find the minimum r0 = [2;2]; %%initial guess on x is 10 and my initial guess on y is 10 alfa = 0.1; for index = 1:1000 plot3(r0(1),r0(2),f(r0(1),r0(2)),'r*','MarkerSize',20) r0 = r0 - alfa*inv(fdblprime(r0(1),r0(2)))*fprime(r0(1),r0(2)); end r0 f(r0(1),r0(2)) function z = f(x,y) %z = (x+2).*(x-2).*(x-4).*(x+4) + y.^2; %z = (x.^2 - 4).*(x.^2-16) + y.^2; z = x.^4 - 20.*x.^2 + 64 + y.^2; function zprime = fprime(x,y) %%Gradient which is a vector dfdx = 4*x.^3 - 40*x; dfdy = 2*y; zprime = [dfdx;dfdy]; function zdblprime = fdblprime(x,y) %Jacobian which is a matrix df2dx2 = 12*x.^2 - 40; df2dxdy = 0; df2dy2 = 2; df2dydx = 0; zdblprime = [df2dx2 df2dxdy ; df2dydx df2dy2];
@abdullahomair2811
@abdullahomair2811 8 жыл бұрын
Thanks dude
@alibaskan9200
@alibaskan9200 5 жыл бұрын
Hello Dr Carlos, thanks for the video and it is really helpful for me. Im new at Matlab so I want to ask you about function command. I know that it should have ended with "end" but you didnt use "end" in their last line. I have tried them with "end" and it has already smulated it. But in some another projects it doesnt work without "end" Why? can you explain this for me ?
@CarlosMontalvo251
@CarlosMontalvo251 5 жыл бұрын
You just have to be consistent. If you use end in one function you have to use end in another. I prefer not to use end just because it's less typing
@alibaskan9200
@alibaskan9200 5 жыл бұрын
@@CarlosMontalvo251 Thanks for your reply.
@alibaskan9200
@alibaskan9200 5 жыл бұрын
​@@CarlosMontalvo251 I have another question for you :) what is alfa = 0.2 there is no anyhing like this in general formula.
@CarlosMontalvo251
@CarlosMontalvo251 5 жыл бұрын
@@alibaskan9200 Alfa is a user parameter that is dependent on your system. Think of it like a control gain or a knob you can tune. If the number is big the system could go unstable. If it's too small the system may take too long to converge. There is a happy medium to ensure convergence and not create an instability.
@alibaskan9200
@alibaskan9200 5 жыл бұрын
@@CarlosMontalvo251 Thank you, you have really helped me.
@zeepan4443
@zeepan4443 6 жыл бұрын
Hi, How to solve if any function have four variables , etc f(w,x,y,z) ?
@CarlosMontalvo251
@CarlosMontalvo251 6 жыл бұрын
You just add more dimensions to the gradient and the jacobian.
@zeepan4443
@zeepan4443 6 жыл бұрын
I tried but failed. Sir, would you please help me? its my project part.
@zeepan4443
@zeepan4443 6 жыл бұрын
Sir, for example in following example, if i added one more variable named 'm' as given in following example, function newton2D() clc close all x=-10:0.1:10; y=-10:0.1:10; m=-10:0.1:10; [xx,yy,mm]=meshgrid(x,y,m); zz=f(xx,yy,mm); mesh(xx,yy,mm,zz) %find that where f-0? r0=[10;10;10]; %Initial guess on X, and Y are 10 alfa=0.2; while abs(f(r0(1),r0(2),r0(3)))>1e-6 r0=r0-alfa*f(r0(1),r0(2),r0(3))./fprime(r0(1),r0(2),r0(3)); end hold on plot3(r0(1),r0(2),r0(3),0,'rs','MarkerSize',20) function z=f(x,y,m) z=x.^2+y.^2-25+m.^2; function zprime= fprime(x,y,m) z=x.^2+y.^2+m.^2-25; dfdx=2*x; dfdy=2*y; dfdm=2*m; zprime=[dfdx;dfdy;dfdm]; then i received following error while simulating it.
@zeepan4443
@zeepan4443 6 жыл бұрын
Error using matlab.graphics.chart.primitive.Surface/set While setting the 'XData' property of 'Surface': Value must be a vector or 2D array of numeric type Error in matlab.graphics.chart.internal.ctorHelper (line 6) set(obj, pvpairs{:}); Error in matlab.graphics.chart.primitive.Surface Error in mesh (line 139) hh = matlab.graphics.chart.primitive.Surface('XData',x,'YData',y,'ZData',z,'CData',c,... Error in newton2D (line 10) mesh(xx,yy,mm,zz)
@CarlosMontalvo251
@CarlosMontalvo251 6 жыл бұрын
You can't just arbitrarily add an extra variable everywhere. Meshgrid is soley used for plotting and you can't plot 3 dimensional functions. You're getting an error because of that. What I'm saying is that the mesh function only takes 3 arguments. If you are missing that then you do not understand what the underlying mechanics are of the problem and I can't help you from my keyboard or from youtube. I suggest you talk to one of your professors or colleagues in person to help you.
@andressuarez7503
@andressuarez7503 6 жыл бұрын
hi good night how can I contact you
@metroidandroid
@metroidandroid 5 жыл бұрын
"If you can do it in 2 dimensions you can do it in 5 dimensions", that's the equivalent of 2setviolin "if you can play it slow, you can play it fast" lol
@CarlosMontalvo251
@CarlosMontalvo251 5 жыл бұрын
Haha. Programming is a bit different. Once you've vectorized you're code there is no limit to how big you can make the vector unless you max out on computer memory
@keithkelly6197
@keithkelly6197 5 жыл бұрын
Make the font size bigger
@CarlosMontalvo251
@CarlosMontalvo251 5 жыл бұрын
gitlab.com/Montalvo/MATLAB_Games.git just download the code
@sebastianossandon2532
@sebastianossandon2532 8 жыл бұрын
I have to program this method in a way you can input N numbers of variables and equations and the program calculates its derivatives (not using matlab functions) and solution... I don't even know how to start lol.
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
What you probably want to do is start with computing derivatives numerically kzbin.info/www/bejne/qnWTin6cltWmg5Y
@sebastianossandon2532
@sebastianossandon2532 8 жыл бұрын
I do have a method to do that, my main issue is to expand things to work for n variables, specially the jacobian.
@CarlosMontalvo251
@CarlosMontalvo251 8 жыл бұрын
Oh man. Yea that is tough. I feel like I've done this before though. I wonder if I dig through my notes I can find something
@sebastianossandon2532
@sebastianossandon2532 8 жыл бұрын
Oh that would be so helpful... any hint is welcome lol.
@whentutv7415
@whentutv7415 7 жыл бұрын
Hi Sebastian, Did you succeed ? I am also having the same problem. Could you help me please
@mathematical_fun_with_Sumbel
@mathematical_fun_with_Sumbel 5 жыл бұрын
Increase font size plz
@CarlosMontalvo251
@CarlosMontalvo251 5 жыл бұрын
Too late now. I'll do it next time
@mathematical_fun_with_Sumbel
@mathematical_fun_with_Sumbel 5 жыл бұрын
Please do something sir, my research work base on this code. Sir can u please send m the video if possible
@CarlosMontalvo251
@CarlosMontalvo251 5 жыл бұрын
@@mathematical_fun_with_Sumbel It would probably be easier for you to just download the code. It should be on this repo gitlab.com/Montalvo/MATLAB_Games.git
@danielcm81
@danielcm81 7 жыл бұрын
click, click, click, blah, blah, blah, click, click, click, blah.
MATLAB Help - Output Error Method
17:43
Monte Carlos
Рет қаралды 3,9 М.
Two-Dimensional Newton-Raphson
16:07
John Gardner
Рет қаралды 11 М.
Ik Heb Aardbeien Gemaakt Van Kip🍓🐔😋
00:41
Cool Tool SHORTS Netherlands
Рет қаралды 9 МЛН
А ВЫ УМЕЕТЕ ПЛАВАТЬ?? #shorts
00:21
Паша Осадчий
Рет қаралды 1,8 МЛН
When you discover a family secret
00:59
im_siowei
Рет қаралды 20 МЛН
How I Did The SELF BENDING Spoon 😱🥄 #shorts
00:19
Wian
Рет қаралды 37 МЛН
MATLAB Help - Optimization (Step Search/Grid Search)
14:32
Monte Carlos
Рет қаралды 17 М.
MATLAB Nonlinear Optimization with fmincon
14:26
APMonitor.com
Рет қаралды 239 М.
MATLAB Help - Quadratic Splines
8:58
Monte Carlos
Рет қаралды 16 М.
Newton's method for solving nonlinear systems of Algebraic equations
18:37
Compute and Evaluate Jacobian Matrix Matlab
4:40
lorenzo donadio
Рет қаралды 38 М.
Fourier Transform, Fourier Series, and frequency spectrum
15:46
Physics Videos by Eugene Khutoryansky
Рет қаралды 3,1 МЛН
Ik Heb Aardbeien Gemaakt Van Kip🍓🐔😋
00:41
Cool Tool SHORTS Netherlands
Рет қаралды 9 МЛН