Octave coding -- solving a quadratic equation and then using the roots

In summary, you could solve the equation by substituting x1 and x2 into the equation and solving for y.
  • #1
Ugnius
54
10
Homework Statement
.
Relevant Equations
.
Hi , I had to solve a quadratic equation , i got two roots as an answer ( ans= x1 / x2) , and now i need to use one of those answers to complete further tasks like finding y from x+y=c so i need to use x1 and x2 from roots , i was wondering if that's possible and how
 
Physics news on Phys.org
  • #2
Ugnius said:
Homework Statement:: .
Relevant Equations:: .

Hi , I had to solve a quadratic equation , i got two roots as an answer ( ans= x1 / x2) , and now i need to use one of those answers to complete further tasks like finding y from x+y=c so i need to use x1 and x2 from roots , i was wondering if that's possible and how
It seems like you've already done the hard work. The equation ##x + y = c## is equivalent to ##y = -x + c##. Can't you just substitute x1 and x2 here and find y?
 
  • #3
Mark44 said:
It seems like you've already done the hard work. The equation ##x + y = c## is equivalent to ##y = -x + c##. Can't you just substitute x1 and x2 here and find y?
yea that what i am not able to do because i don't know what function i need to call to get the root1 and root2 as variables
 
  • #4
i will explain the task - i have to calculate equation system (1.) 6x^2 + 3y^2 = 12 (2.) x+y=2 ; so i can get the x1 and x2 by calculating the first one using substitution , making matrix and calculating roots , but then i need to get y1 and y2 , but i don't know what function i use after the root.
 
  • #5
Have you written a function that calculates the roots of a quadratic? Your function, if you have one, should return two values. Show us the Octave code you have.
 
  • #6
Mark44 said:
Have you written a function that calculates the roots of a quadratic? Your function, if you have one, should return two values. Show us the Octave code you have.
I have solved it 3 AM last night , the point was that roots was a 1x2 matrix , but i could use because it was plugged in octave variable so i created another 1x2 matrix , made it equal to roots(A) matrix , and then i could use B(1) and B(2) to get 1st and 2nd root as variables , thanks for the help tho !
 

1. How do I solve a quadratic equation using Octave coding?

To solve a quadratic equation using Octave coding, you can use the built-in function "roots". This function takes in the coefficients of the quadratic equation as input and returns the two roots as output. For example, if your quadratic equation is ax^2 + bx + c = 0, you can use the code "roots([a b c])" to solve it.

2. What if my quadratic equation has complex roots?

If your quadratic equation has complex roots, Octave will return them in the form of a complex number. For example, if the roots are 2+3i and 2-3i, Octave will return the complex number 2+3i as the first root and 2-3i as the second root. You can use the "real" and "imag" functions to separate the real and imaginary parts of the complex number.

3. Can I solve multiple quadratic equations at once using Octave coding?

Yes, you can solve multiple quadratic equations at once using Octave coding. You can create a matrix where each row represents the coefficients of a different quadratic equation, and then use the "roots" function on the entire matrix. Octave will return a matrix with the roots of each equation in the corresponding rows.

4. How do I check if the roots returned by Octave are correct?

You can check if the roots returned by Octave are correct by plugging them back into the original quadratic equation. If the result is close to zero, then the roots are correct. You can also use the "polyval" function to evaluate the polynomial with the roots as input, and if the result is close to zero, the roots are correct.

5. Can I graph the quadratic equation and its roots using Octave?

Yes, you can graph the quadratic equation and its roots using Octave. You can use the "plot" function to graph the equation, and then use the "hold on" and "plot" functions to add the roots to the graph. This will show the intersection points of the equation and the x-axis, which are the roots. You can also use the "scatter" function to plot the roots as points on the graph.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
888
  • Precalculus Mathematics Homework Help
Replies
11
Views
516
  • STEM Educators and Teaching
2
Replies
36
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
Replies
2
Views
749
  • Precalculus Mathematics Homework Help
Replies
3
Views
1K
  • Precalculus Mathematics Homework Help
Replies
5
Views
874
  • Introductory Physics Homework Help
Replies
4
Views
889
  • Precalculus Mathematics Homework Help
Replies
5
Views
685
  • Engineering and Comp Sci Homework Help
2
Replies
42
Views
2K
Back
Top