In this screencast, we discuss the basics of Matlab's function fsolve, which can be used to solve systems of non-linear equations.
Пікірлер: 29
@vjdipchan64365 жыл бұрын
Thank you for your in-depth demonstration of the fsolve function. Much appreciated!
@danielgladstone17893 жыл бұрын
Interesting haha
@LaraxWarrior33 жыл бұрын
Thank you
@danielt.plazas54014 жыл бұрын
Thank you Dr Gregory Reeves! Do you know if there is any way to find all the roots of a system in which there is, for example, an equation with two unknowns? Of course in a finite range.
@drgregoryreeves4 жыл бұрын
Sorry for the slow reply. In general, there is no way to do that, as far as I know. For some kinds of equations, you can be sure about all the roots (if the equations are polynomials, for example). But non-linear equations might not have any roots, and you wouldn't know that. Also, within a finite range that you specify, you might not be in the right range. For one equation with two unknowns, though, then you have an underspecified system. You'd need either another equation, or you'd need to specify one of your unknowns. If you have enough computing power, and you want to be very sure, you can always plot the equation for many values of your unknown within your finite range, and see how many times it crosses the x-axis. You can usually be pretty sure your equation is "smooth", so that you won't be missing any roots as long as you have a high enough density of points. This is a very brute force method, so it's very slow.
@jabbamafmgeneralenterprise4992 жыл бұрын
Up dad's ok Sid 😜 don't mind 😊😊 dude do dinner 🍽️🍽️🍽️🍽️🍽️🍽️ I can 😂😂😂😂😂😂😂😂 up 😜🐱🐱🐱🐱 I can I can help
@jabbamafmgeneralenterprise4992 жыл бұрын
U dey up for me up 😅☺️ up in my head is not 🚫🚫
@jabbamafmgeneralenterprise4992 жыл бұрын
U dey up for me up 😅☺️ up in my head is not 🚫🚫
@jabbamafmgeneralenterprise4992 жыл бұрын
U dey e for
@sefaarslan14882 жыл бұрын
I have a system with 10 equations and 8 unknowns, how can I solve these equation sets?
@GregReeves15202 жыл бұрын
If you have an overdetermined system, fsolve can still work with it, but it will try to do some sort of optimization to get the best fit values of your unknown that minimizes your 10 equations in some way. I am not 100% sure how that works, since I've only tried to use fsolve with square systems. Are you trying to do an optimization problem?
@sefaarslan14882 жыл бұрын
@@GregReeves1520 no, I'm dealing with trim analysis of an aircraft in forward flight and trying to find the unknowns from dynamic equations. Thanks for your reply I will try f solve first
@saddamhussainsoomro28104 жыл бұрын
Sir can you help me for 12 non linear equations with 12 variables, or guide anything please. Thanks
@GregReeves15204 жыл бұрын
Hi, happy to help. Can you clarify? Are you running into problems that are not helped by this video? fsolve can, in principle, handle a 12x12 system, but it may be difficult and you might need to use a very good initial guess. Have you already tried to program a script and function to use fsolve on your system? What did you find? Was there a particular error?
@saddamhussainsoomro28104 жыл бұрын
@@GregReeves1520 yes sir I tried using fsolve. That shows error. The equation not solved! I also tried Newton raphson method but the roots are coming to be same as my initial guesses.
@GregReeves15204 жыл бұрын
@@saddamhussainsoomro2810 If you have already taken the time to write a Newton's method code to solve the problem, I would focus on that. So you wrote a while loop that quits when either "f" or "delta_x" (or both) become small (say, 1e-6). In each iteration of the loop, you need to evaluate "f", calculate the Jacobian "J", then take a newton step of "delta_x = -J \ f; x = x + delta_x;" Correct? How many iterations are happening in the while loop? If your solution is the same as your initial guess, then my guess is that either you are not entering the while loop correctly, or within the while loop, you are not updating your value of x. Thoughts?
@saddamhussainsoomro28104 жыл бұрын
@@GregReeves1520 sir can you send me email I will send you my code
@drgregoryreeves4 жыл бұрын
@@saddamhussainsoomro2810 I am not planning on posting my email publicly here, but you can google me, and you can probably find me on an NC State website.
@criccenter96193 жыл бұрын
How can I plot (X,Y) When X=-3:0.1:3; Y=X² + 3*Y - exp(X-2*Y);
@drgregoryreeves3 жыл бұрын
You can convert your equation to the form f(X) = 0 by moving the lone Y on the LHS to the RHS. Then, in that form, you can run a for loop to use fzero to solve for Y for every X in your mesh. Alternatively, you could use fsolve once instead of fzero in a for loop...that might work too. Let me know if you have other questions. Once you have a value of Y for every value of X, you can plot(X,Y).
@criccenter96193 жыл бұрын
@@drgregoryreeves x=[-3:0.05:3]; n = size(x,1); yy=zeros(n,1); for i=1:n yy(i)=fsolve(@(y) fun(x(i),y),0); end plot(x,yy) function S=fun(x,y) S=X²+3*Y-exp(X-2*Y) end I used still unable to get answer please suggest your code more precisely
@drgregoryreeves3 жыл бұрын
@@criccenter9619, when you say "unable to get answer", does that mean you can't get any kind of solution? Or is it that you are not getting the solution you expect? Because your code looks good, syntax-wise. The only thing is that in your first post, you had a "Y" on the LHS of your equation, but that "Y" is gone in your second post. If the first post is correct, you should move that "Y" from the LHS to the RHS, so it appears as a "-Y" in the RHS of the "S" equation in your function. Did that help? Let me know!
@criccenter96193 жыл бұрын
@@drgregoryreeves I am sorry I made mistake in editing there S=Y-(X² + 3*Y - exp(X-2*Y)); I wasn't able to get anything on plot .Nothing except the axis. Please provide your solution if u don't mind.
@drgregoryreeves3 жыл бұрын
@@criccenter9619 It sounds like your equation didn't converge, and you got a bunch of NaN's for your elements in the "yy" vector. Can you double check that?