Solving Systems of Nonlinear Algebraic Equations in Matlab

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ม.ค. 2025

ความคิดเห็น • 93

  • @ThunderBullet13
    @ThunderBullet13 4 ปีที่แล้ว

    I've been struggling to solve 4 equations with 4 unknowns using the Newton iterative numerical method.
    The problem was that my matlab code works fine but an initial guess has to be good enough to work properly so I used the 'fsolve' you described in your video to find the exact solutions for my 4 equations by testing various initial guesses and came out with the solution then I used the true value and the initial guesses from the 'fsolve' into my code and to my surprise it worked just as expected !
    Thanks and god bless you.

  • @OSRS2ndBase
    @OSRS2ndBase 5 ปีที่แล้ว

    Great video, thanks for taking the time to make this!

  • @shihaowang152
    @shihaowang152 10 ปีที่แล้ว

    Very clear presentation! Thank you!

  • @mohamedshabara1138
    @mohamedshabara1138 11 ปีที่แล้ว

    @ jake Blanchard
    The Matlab is showing an error when I try to solve 3 non-linear equations
    Power-(phi*sigma*row4*Q4.*((w*­D5.)^2))=0;
    dsc*(Q4.^0.5)-D5.*(deltah.^0.2­5)=0;
    nsc*(deltah.^0.75)-w*(Q4.)^0.5­=0;
    The three unknowns are Q4,deltah,D5

  • @btsjoayo
    @btsjoayo 12 ปีที่แล้ว

    what about finding the constant value of a function?
    Find the constant values a, b, c & d for f(x) = ax^3+bx^2+cx+d given that f(-3) = -112, f(-1)=-2 and f(2)=13

  • @bangthatdrumb
    @bangthatdrumb 13 ปีที่แล้ว

    Is there a method to find ALL roots of a system of nonlinear equations?

  • @jasonjohnson195
    @jasonjohnson195 14 ปีที่แล้ว

    @jakeblanchard
    Although I managed to solve it alone, I would like to say you a big thank you for all the videos you have posted in youtube. Especially the "using Simulink to Solve Ordinary Differential Equations" was really very helpful.

  • @tigerrx7
    @tigerrx7 12 ปีที่แล้ว

    If I have 4 equations with 4 unknowns, can I just assume the value for 1 variable and matlab calculate the other values based on that iterative assumed value??? Thanks. This is from fluid mechanics involving Velocity (V), Reynolds Number (Re), Friction factor (f) and volume flow rate (Vdot). Thank you

  • @jasonjohnson195
    @jasonjohnson195 14 ปีที่แล้ว

    Hello! Do you know how to solve as nonlinear system of ordinary differential equations?
    I think it can be done using Runge - Kutta or Lotka-Volterra. Do you have something ready?

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    You should be able to use anonymous functions to do this. It's documented reasonably well in the standard Matlab documentation.

  • @doc_microscope
    @doc_microscope 6 ปีที่แล้ว

    Good afternoon, i have a problem: I have this linear system of 4 equations in four unknows P1, P2 P3 and P4:
    a1*P1+a2*P2+a3*P3+a4*P4=a;
    b1*P1+b2*P2+b3*P3+b4*P4=b;
    c1*P1+c2*P2+c3*P3+c4*P4=c;
    d1*P1+d2*P2+d3*P3+d4*P4=d;
    a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4 are constants and a,b,c,d are the known terms.
    How i can implement it on Matlab such that to find the roots?

    • @jakeblanchard
      @jakeblanchard  6 ปีที่แล้ว +1

      For that you can use the "\" operator. This video might help: www.mathworks.com/videos/solving-linear-equations-97489.html

  • @SweetAqui30
    @SweetAqui30 11 ปีที่แล้ว

    Hi I was wondering if u can also say how to plot those 2 equations and the solution

  • @jakeblanchard
    @jakeblanchard  12 ปีที่แล้ว

    I'm not sure. Can you send me your script?

  • @bangthatdrumb
    @bangthatdrumb 13 ปีที่แล้ว +1

    @jakeblanchard i used continuation software XPAUTT and counted them manually, horay!

  • @luansol
    @luansol 11 ปีที่แล้ว

    Hi,
    I'm trying to make an optimization program for B-series propellers and one of the steps is to find solutions of KT-KQ polynomials in terms of pitch and area ratio.
    What i would like to know is if fsolve accepts boundary conditions, and how can i declare those (couldn't find anything like in matlab help). The boundary conditions are for the solutions (something like 0.5

  • @nitinverma4222
    @nitinverma4222 12 ปีที่แล้ว

    hi ,
    actually i was trying to solve a single trigonometric equation . but in the output it gives something like this "6.2839*k + z1". what is k? what is z1?

  • @nitinverma4222
    @nitinverma4222 12 ปีที่แล้ว

    Hi,
    how can we solve trigonometric equations using matlab.??

  • @saeidsaeidabadi7757
    @saeidsaeidabadi7757 11 ปีที่แล้ว

    hi.can i use it for 7 nonlinear equations?

  • @olivercampbell1985
    @olivercampbell1985 11 ปีที่แล้ว

    what if you have constants that you want to pass into the function? how do you do that?

  • @betincb
    @betincb 11 ปีที่แล้ว

    I'd like to know if you could help me in order to solve a Rosenbrock's function applying a quasi-newton method (BFGS). It would be very helpful . Thanks in advanced.

  • @1031194657
    @1031194657 11 ปีที่แล้ว

    hi
    what if inputs are array of symbolic values which we have calculated in main code. and we just want to solve the nonlinear equation equal to zero symbol as our variable

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    I'm not sure what the question is. If you correct the first line to make it an equation and assuming there is a solution, then the approach outlined above should be able to solve it.

  • @chirantanpramanik3209
    @chirantanpramanik3209 10 ปีที่แล้ว +1

    thank you Sir. This is very helpful for me.

  • @sooooleh
    @sooooleh 4 ปีที่แล้ว

    what is the difference between ode 45 and fsolve for solving nonlinear ode?

    • @jakeblanchard
      @jakeblanchard  4 ปีที่แล้ว

      Fsolve solves nonlinear algebraic equations. It won't solve an ode unless you first convert to an algebraic system (with finite differences, for example).

  • @asr10g
    @asr10g 11 ปีที่แล้ว

    I'm not that well versed in matlab, so this might be a dumb question, but why did you put periods after the variables x and y if you were raising them to a power?

    • @jakeblanchard
      @jakeblanchard  11 ปีที่แล้ว +1

      If x and y are vectors, then x*y will try to multiply x and y are vectors. This will only works if the two vectors have appropriate dimensions. If you want to multiply the first element in x by the first element in y, the second element in x by the second element in y, etc., then you do x.*y, That is .* gives you element by element multiplication. The other operators, such as ./ and .^ work similarly.

  • @rlovelace7
    @rlovelace7 10 ปีที่แล้ว

    Jake Blanchard thank you so much for the video! I have a system of four equations and four unknowns that I was attempting to solve using your method, unfortunately I keep getting a message saying that "Solver stopped prematurely" and I don't think it is converging.
    "fsolve stopped becaue it exceeded the function evaluation limit, options.MaxFunEvals=400 (the default value)" and I am not sure how to change this so that it doesn't stop prematurely. Do you have any advice on this?
    Thank you

  • @ibrahimsekmenoglu6253
    @ibrahimsekmenoglu6253 5 ปีที่แล้ว

    What are the starting points? I did not understand.

    • @jakeblanchard
      @jakeblanchard  5 ปีที่แล้ว

      I'm not sure I understand the question. This solver is iterative, so you have to provide an initial guess to get it started. In this case, I provide guesses for x and y. I guessed that the solution was x=2 and y=3 so I began the script with guess=[2,3];
      For some problems, the solver will converge for a wide variety of guesses, while for others, you need to be fairly close in order to reach convergence.

    • @ibrahimsekmenoglu6253
      @ibrahimsekmenoglu6253 5 ปีที่แล้ว

      @@jakeblanchard
      I'm sorry, I don't know English. Homework: Newton Raphson (jacobian matrix) MATLAB code solving the question. Can you help me.

  • @emiliowills8897
    @emiliowills8897 11 ปีที่แล้ว

    I have been trying to maximize a constrained utility function but I dont know how to solve it in matlab. Can you give me some advice please?

    • @jakeblanchard
      @jakeblanchard  11 ปีที่แล้ว +1

      I'm pretty sure you need the optimization toolbox if you want to use a built-in function for constrained optimization.

  • @r4id1337
    @r4id1337 7 ปีที่แล้ว +1

    Hey really nice video :)
    I hope you can help me:
    I want to know the solution for x1 of the following function (i know u1,u2,u3):
    u1=(u2-x1)/ln((u2-u3)/(x1-u3))
    What i have to write ?
    I know i need to use fsolve but i have really absolutly no idea what the code looks like.
    I need this to insert it as Interpreted Matlab function with u1, u2 and u2 as input.

    • @jakeblanchard
      @jakeblanchard  7 ปีที่แล้ว

      Actually, since this is one equation and one variable, you can use fzero. You need to create a function that defines your equation and then call it from fzero.

  • @naveed6396
    @naveed6396 3 ปีที่แล้ว

    How to proceed when the coefficients are matrices but not numbers
    Thanks in advance

    • @jakeblanchard
      @jakeblanchard  3 ปีที่แล้ว

      If your equations are linear, you don't need fsolve. You can just use the "\" operator. If they are nonlinear, but the coefficients are in a matrix, then you can use matrix multiplication to generate your functions. In my video, the fcn variable is a vector that we create one element at a time. You can just as easily create it in one command if your coefficients are in a matrix. If this doesn't make sense, post an example and I can give some code that will solve the problem.

    • @naveed6396
      @naveed6396 3 ปีที่แล้ว

      @@jakeblanchard Let H=[1 1;1 -1] , P=[0.5 0.25, 0.5 0.75] then how to solve the system
      H*x+P*x*y-25=0
      x+P*x-2*y+7=0 with guess=[1 2]
      It is a case of non-linear... thanks

    • @jakeblanchard
      @jakeblanchard  3 ปีที่แล้ว

      @@naveed6396 I don't think I've ever seen a set of equations expressed this way. If you have two unknowns (x and y) and they are not vectors, then you should only have two equations. But this system represents 8 equations. That is, H*x represents a 2x2 matrix. So the first equation, with all the terms, also represents a 2x2 matrix that must equal 0. So the only way to do that would be for each term in that matrix to be 0. That is 4 equations.

    • @naveed6396
      @naveed6396 3 ปีที่แล้ว

      @@jakeblanchardthanks sir... i think it goes complicated here...we can also use Newton raphson method but I am stucked there also.

    • @jakeblanchard
      @jakeblanchard  3 ปีที่แล้ว

      @@naveed6396 You shouldn't worry about a solution method until you first understand your equations. As I understand them, you have too many equations. You should make sure a solution exists before you try to solve them numerically.

  • @Mhibrahimi
    @Mhibrahimi 11 ปีที่แล้ว

    @ Jake blanchard
    what about system of equations
    cos(a)+cos(b)+cos(c)+cos(d)-4;
    cos(3*a)+cos(3*b)+cos(3*c)+cos(3*d)=0
    fcos(5*a)+cos(5*b)+cos(5*c)+cos(5*d)=0
    cos(7*a)+cos(7*b)+cos(7*c)+cos(7*d)=0.

  • @leyla6872
    @leyla6872 11 ปีที่แล้ว

    Hello, I wonder if you can give some guidance about the nonlinear dynamic system that i am working on it. i applied two different methods, my method works for some specific range and beyond that range the steady states are not in agreement with the result of my numerical simulation. I do appreciate if you can give me any advice .
    With many thanks

    • @jakeblanchard
      @jakeblanchard  11 ปีที่แล้ว

      It's hard to say without seeing the system of equations. Feel free to send them to me if you want me to take a look. Have you tried reducing the tolerances using the options statement?

    • @leyla6872
      @leyla6872 11 ปีที่แล้ว

      Thanks for your quick reply.
      This is part of my code, I have four variable Qe, Qi, Qr, Qs which are firing rates and they are related to voltages (Ve, Vi, Vr, Vs) by sigmoid function, each set of steady states correspond to different coefficients
      system equations
      ve = c1*Qe +c2*Qi + c3*Qs
      vi = c4*Qe +c5 *Qi +c6*Qs
      vs = c7 +c8*Qe + c9*Qr
      vr = c10*Qs + c11*Qe
      here is part of my matlab code
      Q =@(V) Qmax ./(1 + exp(-(V - Theta)/Sigma));
      V =@(Q) Theta - Sigma.*log((Qmax./Q - 1));
      eq1 = V(Qe) - coeff(1,1)*Qe - coeff(1,2)*Qi - coeff(1,4)*Qs;
      eq2 = V(Qi) - coeff(2,1)*Qe - coeff(2,2)*Qi - coeff(2,4)*Qs;
      eq3 = V(Qr) - coeff(3,4)*Qs - coeff(3,1)*Qe;
      eq4 = V(Qs) - H./etha(1,1) - coeff(4,1)*Qe - coeff(4,3)*Qr;
      qe = solve(eq1,eq2,eq3, eq4);
      qe = double([qe.Qe qe.Qi qe.Qr qe.Qs]);
      VV = V(qe);
      I applied this method and i got the result which are in agreement with the result of the article but when I go beyond that range I can not get right behaviour.
      I try to solve the steady state according Ve, Vi, Vr and Vs and i got different result !!
      syms Ve Vi Vr Vs positive
      Q =@(V) Qmax ./(1 + exp(-(V - Theta)/Sigma));
      eq1 = Ve - coeff(1,1)*Q(Ve) - coeff(1,2)*Q(Vi) - coeff(1,4)*Q(Vs);
      eq2 = Vi - coeff(2,1)*Q(Ve) - coeff(2,2)*Q(Vi) - coeff(2,4)*Q(Vs);
      eq3 = Vr - coeff(3,4)*Q(Vs) - coeff(3,1)*Q(Ve);
      eq4 = Vs - H./etha(1,1) - coeff(4,1)*Q(Ve) -coeff(4,3)*Q(Vr);
      qe = solve(eq1,eq2,eq3, eq4);
      qe = double([qe.Ve qe.Vi qe.Vr qe.Vs]);
      I can email you my code and my the results if it could be helpful.
      I do appreciate your help.

    • @jakeblanchard
      @jakeblanchard  11 ปีที่แล้ว

      Leyla Noroozbabaee
      Yes, it would probably be easier if I could try to run your scripts. Just email them to me.

  • @sidani87
    @sidani87 11 ปีที่แล้ว

    I have solved the problem with the non linear equations with 6 unknowns...3 of the variables are coming out with correct answers but for the remaining three I am getting imaginary parts which is not correct..I am emailing you my code on your email..please let me know if I have made any errors in coding it...

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    Send me your script. I can't tell what's wrong without seeing some code.

  • @kylecroft6647
    @kylecroft6647 9 ปีที่แล้ว

    If I want to solve for multiple solutions can I enter multiple guesses at once? Or is there a easier way to do this?
    Thanks

    • @jakeblanchard
      @jakeblanchard  9 ปีที่แล้ว

      Kyle Croft You just have to call fsolve again each time you want to try a new guess.

    • @kylecroft6647
      @kylecroft6647 9 ปีที่แล้ว

      Ok, thanks. So in this problem I was told there were 3 solutions, but is there any way for knowing if there are multiple solutions? Otherwise I would have gotten 1 and just went to the next problem. Thanks again for the quick response.

    • @jakeblanchard
      @jakeblanchard  9 ปีที่แล้ว

      Kyle Croft If it's a function of one variable, then you can just plot the function and look for roots. If it is multiple variables, then it is a little more difficult. Some families of functions allow one to deduce the number of solutions, but not always. Some have infinite solutions; some have none.

  • @micheleschirru7478
    @micheleschirru7478 12 ปีที่แล้ว

    thank you for the vid!

  • @sidani87
    @sidani87 11 ปีที่แล้ว

    I am trying to solve an electrical circuit and I have 19 variables...of which 6 are unknown and the rest are known....I have ended up with 6 non linear equations and 6 algebraic equations with all of them.....can you help me to solve it?Thanks in advance.

    • @jakeblanchard
      @jakeblanchard  11 ปีที่แล้ว

      It should work just like in this video, except everything will be three times larger. If you email me, I can send you the code from the video.

    • @jadefun5320
      @jadefun5320 10 ปีที่แล้ว

      Jake Blanchard Good morning sir, i really have a problem solving system of 6 variables equations of my master thesis.i have followed your video which is actually helpful but the answers are not satisfying the equations in question. moreover the results were expected to be all posetive values. i urgently needs your advice .Thank u in advance

    • @jakeblanchard
      @jakeblanchard  10 ปีที่แล้ว

      Jade Fun If you send me a script, I can take a look at it.

  • @husseinalgusab4129
    @husseinalgusab4129 10 ปีที่แล้ว

    Thank you very much for your very good presentation and can you please send us the presentation that you are used in this presentation thank you

    • @jakeblanchard
      @jakeblanchard  10 ปีที่แล้ว +1

      You can download them from my web site. Go to
      http blanchard ep wisc edu (you have to fill in the dots)
      and then click on Introduction to Matlab. You can find the slides there.

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    It isn't too difficult. For example, if you want to plot f=x^2 you can use the following commands
    x=1:0.1:5;
    f=x.^2;
    plot(x,y)
    To use the functions mentioned in this video, I think you could do this:
    x=1:0.1:5;
    y=fcns(x);
    plot(x,y(:,1),x,y(:,2)
    I don't have access to Matlab right now, so I can't test this.

    • @yogendrasinghbhandari2596
      @yogendrasinghbhandari2596 4 ปีที่แล้ว

      Hi Jake,
      I am trying to deploy fsolve in a problem I face. The only problem is the unknowns I am trying to find are random and I have no idea what to give in the initial guess. What do you suggest? Fsolve will be of any help?

    • @jakeblanchard
      @jakeblanchard  4 ปีที่แล้ว

      @@yogendrasinghbhandari2596 You should be able to come up with some kind of initial guess that depends on the inputs. You need to look at the equations and see if you can come up with something. I can take a look if you send me the equations. The requirements for the initial guess depend on the problem. Sometimes it hardly matters what the guess is, while others require a very good guess to get convergence.

    • @yogendrasinghbhandari2596
      @yogendrasinghbhandari2596 4 ปีที่แล้ว

      @@jakeblanchard
      Honestly, Jake the equations are very messy and it's hard to eye ball them and make a guess for the solution. Still I ll give it a shot. Anyways besides fsolve, do you know of any other tool that can help solve me system of non linear equations? Mathematica perchance?

    • @jakeblanchard
      @jakeblanchard  4 ปีที่แล้ว

      @@yogendrasinghbhandari2596 I haven't used Mathematica for quite a while. I'm sure it has tools for solving nonlinear equations, but I'm not sure how they compare to fsolve. I think you'll still need a guess.

  • @jakeblanchard
    @jakeblanchard  12 ปีที่แล้ว

    You can plug your values from f(-3)=-112, etc., into the function, but that only gives you three equations. Unfortunately, you have four unknowns.

  • @zainabesa4339
    @zainabesa4339 9 ปีที่แล้ว

    please can you tell me, if possible to solve the following equation
    Gamma(x)=1-2x^2
    thank you.

    • @jakeblanchard
      @jakeblanchard  9 ปีที่แล้ว +1

      +zainab esa
      Yes, it ought to be able to solve that equation.

  • @marwan_nafea
    @marwan_nafea 11 ปีที่แล้ว

    thank u so much bro :)

  • @Talkingcouch
    @Talkingcouch 9 ปีที่แล้ว

    thank you so much

  • @hajarbelghazdis4473
    @hajarbelghazdis4473 2 ปีที่แล้ว

    please, i want to solve numerically the following equation in matlab: 1=(1/y)x*exp(x*y)

    • @jakeblanchard
      @jakeblanchard  2 ปีที่แล้ว

      That is one equation with two unknown variables. You'll need another equation.

    • @hajarbelghazdis4473
      @hajarbelghazdis4473 2 ปีที่แล้ว

      @@jakeblanchard I want to calculate the value of y for a given x between 0 and 1 with x=0:0.1:1 and then ploting y as function of x.

    • @jakeblanchard
      @jakeblanchard  2 ปีที่แล้ว +1

      @@hajarbelghazdis4473 that makes sense. So Matlab's fzero function should be able to handle that.

    • @hajarbelghazdis4473
      @hajarbelghazdis4473 2 ปีที่แล้ว

      @@jakeblanchard thakn you very much.

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    I don't use the symbolics in Matlab. Maybe someone else can help.

  • @ramannatarajan6613
    @ramannatarajan6613 9 ปีที่แล้ว

    How to simplify an expression like {(4p^2+4q^2+4p+4q+10a)(8p^3+5q^4+8a^2+10)+(3a^4+p^4)} to its simplest form... i dont want to solve it but just simplify it... please help me.

  • @jakeblanchard
    @jakeblanchard  12 ปีที่แล้ว

    I'm not sure what you mean by trigonometric equations. If it's a single equation, you might try fzero. If it's a system of equations, try fsolve.

  • @vanfly
    @vanfly 8 ปีที่แล้ว

    Thank you.

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    The function in this video is overkill for your problem. You just need a root finder. Try the fzero function in Matlab.

  • @jakeblanchard
    @jakeblanchard  12 ปีที่แล้ว

    That makes me nervous. If you know one of the 4 variables, you should be able to pick out any of the other three equations and then solve for the remaining three variables. You could then check these in the fourth equation if you wanted to.

  • @sajjadali6867
    @sajjadali6867 8 ปีที่แล้ว

    if code :
    function fcns=eqs(z)
    x=z(1);
    y=z(2);
    fcns(1)=x.^2+2*y.^2-5*x+7*y-40;
    fcns(2)=2*x.^2-y^2+4*x+2*y-28;
    end
    it gives the result in command window:
    >> equsw Error using equsw (line 3)
    Not enough input arguments.
    plz guide me

    • @jakeblanchard
      @jakeblanchard  8 ปีที่แล้ว

      +sajjad ali
      You can download some sample scripts at my web site blanchard.ep.wisc.edu/PublicMatlab/index.html#Nonlin
      Try that and see if it works.

  • @angkhoanguyen5257
    @angkhoanguyen5257 6 ปีที่แล้ว

    can you help me solve this equation 22.35*log(1.0 - 5.7174/(x - 1.0)) - 29.19*log(0.83811/x + 1.0)=0

    • @jakeblanchard
      @jakeblanchard  6 ปีที่แล้ว

      First plot the function and make sure there is at least one root. Also note, if there is a root, roughly where it is (ie, what value of x). Then fzero should be all you need. You can find some information here: blanchard.ep.wisc.edu/PublicMatlab/#Root

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    I would have to see all the equations. Feel free to send them to me by email.

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    Sure.

  • @jakeblanchard
    @jakeblanchard  11 ปีที่แล้ว

    I'm afraid I've never even heard of BFGS.

  • @eliana.2fun
    @eliana.2fun 10 ปีที่แล้ว

    Thank you

  • @betincb
    @betincb 11 ปีที่แล้ว

    Ok, Thanks anyway.

  • @bangthatdrumb
    @bangthatdrumb 13 ปีที่แล้ว

    er without guessing...