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

AI Thread Summary
The discussion revolves around solving a quadratic equation and using its roots for further calculations. The user initially struggled to extract the roots from a matrix in Octave to use in another equation. After clarification, it was noted that the roots were stored in a 1x2 matrix, which could be accessed by creating a new matrix. The user successfully utilized this method to assign the roots to variables for further calculations. Overall, the exchange highlights the importance of understanding matrix operations in Octave for solving equations.
Ugnius
Messages
54
Reaction score
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
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?
 
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
 
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.
 
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.
 
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 !
 

Similar threads

Replies
7
Views
2K
Replies
8
Views
2K
Replies
1
Views
290
Replies
2
Views
3K
Replies
14
Views
2K
Back
Top