4/11/2024 0 Comments Solve quadratic equation in matlabNote that only the solution nearest to zero was found.įind the points of intersection of the two circles 2x 2 − x + 2y 2 − 8y = 0 and x 2 + 2x + y 2 − 6y + 1 = 0.Ĭlear all % file available in M-files folder as file7.m If you wish, you can follow with soln=double(soln). This indicates that a numerical solution process was needed in “Maple”, and the answer is in variable precision format. However, there is no analytic way to find them. Giving the output angle=Įxample 5: By means of a simple sketch you can see that e x = 4− x 2 has two solutions. The answers are hardly in a form that you would use and so it is better to convert them into numeric values.Īngle=solve(sin(theta)-0.5+cos(theta)) % hardly usableĪngle=double(angle) % looks better in MATLAB But “Maple” can find two solutions exactly. EnterĮxample 4: Unlike Example 3, the equation sin θ = 0.5 − cos θ, −π ≤ θ ≤ π, does not have obvious solutions. However, if for some reason you wanted to solve the same equation for b, you would needĮxample 3: We know sin θ = 0.5 has an infinite number of solutions. In earlier versions of MATLAB, you could useĮxercise: Change to 10/(x^2+1)+2+x=0 and solve again.Įxample 2: Solve the general quadratic equation ax 2 + bx + c = 0 for x. Soln=solve(10/(x^2+1)-4+x) % no need to use f or specify x Or, knowing that x is the default variable, Soln=solve(f,x) % note the three solutions There are various ways:į=10/(x^2+1)-4+x % f is now a symbolic expression This is equivalent to solving 10/x 2 + 1 − 4 + x = 0. If there are two or more symbolic variables, none of which is x, and you forget to specify the one for which the solution is required, it appears to choose the last alphabetical one.ġ0/x 2 + 1 = 4− x. What happens if you do not specify the variable for which the equation is to be solved? If there is only one symbolic variable in the expression, it will solve for it by default. Of course there might be more than one solution for a. To solve a single equation f(x) = 0, this reduces to a=solve(f,x). Here, f1,f2.,fn are symbolic expressions that are to be made zero, v1,v2.,vn are the variables in alphabetical order to be solved for, and a1,a2.,an are the corresponding answers. The command is of the form =solve(f1,f2.,fn,v1,v2.,vn). If this is not possible, it then attempts to find a numeric solution in variable precision format. It firstly attempts to find an exact analytic solution. “Maple” uses the solve facility which can solve n simultaneous algebraic or transcendental equations for n unknowns. You have seen that fzero numerically finds where a function is zero in MATLAB.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |