microsoft / calculator

Windows Calculator: A simple yet powerful calculator that ships with Windows
MIT License
29.73k stars 5.39k forks source link

[Feature] Calculate: Find Roots of an Equation #1522

Open aminoxix opened 3 years ago

aminoxix commented 3 years ago

Hey folks! 👋🏼 Do we have any feature to find the roots of an equation (whether it will a quadratic or linear equation) in one tap?

A quadratic equation is a second-order polynomial equation of a variable say x. The general form of a quadratic equation is given as:

a*x2 + b*x + c = 0

Where a,b and c are real known values and,
a can't be zero.

A quadratic equation has two roots. The roots of a quadratic equation can be easily obtained by using the quadratic formula:

roots = (-b ± √(b2 - 4ac))/2a

Derivation:

ax2 + bx + c = 0

or, ax2 + bx = -c

or, x2 + (b/a)x = -(c/a)

or, x2 + (b/a)x + (b2/4a2) - (b2/4a2) = -(c/a)

or, x2 + (b/a)x + (b2/4a2) = -(c/a) + (b2/4a2)

or, (x + b/2a)2  = -(c/a) + (b2/4a2)

or, (x + b/2a)2  = (b2  - 4ac) /4a2

or, (x + b/2a) = ± √(b2 - 4ac) /2a

or, x = (-b ± √(b2 - 4ac))/2a

There arises three cases as described below while finding the roots of a quadratic equation:

If b2 < 4ac, then roots are complex
(not real).
For example, roots of x2 + x + 1 = 0 are
-0.5 + i1.73205 and -0.5 - i1.73205

If b2 = 4ac, then roots are real 
and both roots are same.
For example, roots of x2 - 2x + 1 = 0 are 1 and 1

If b2 > 4ac, then roots are real 
and different.
For example, roots of x2 - 7x - 12 = 0 are 3 and 4

I didn't have any clue whether, that features is already there or not? If its not, Can I proceed to work on it? Pl help me look out!

MicrosoftIssueBot commented 3 years ago

This is your friendly Microsoft Issue Bot. I've seen this issue come in and have gone to tell a human about it.

ghost commented 3 years ago

This pitch looks like it has everything it needs for review. In the meantime, we'll keep this idea open for discussion so the community has the chance to provide feedback. Check out our New Feedback Process for more info on the user-centered process we follow for new feature development.

aminoxix commented 3 years ago

Sir, I've a blue-print code for this, but doesn't know how to implement it with Microsoft modules/features? Can I take this issue & enhance my knowledge, & work on same issue further?

TrangOul commented 3 years ago

Cubic and quartic equations should also be covered. Closed form solutions exist for them. Linear and quadratic equations can be solved in memory, if the coefficients are "nice". Cubics and quartics - not so easily. And that's a job for Calculator.

aminoxix commented 3 years ago

Can I know @TrangOul, like, specifically what are you talking about? I get, this issue is reg. calculate roots of equations, and you're basically talking about Cubic & Quartics ie, under functions & ranges..

You may refer this, Sir.

TrangOul commented 3 years ago

I mean the equations ax^3 + bx^2 + cx + d = 0 and ax^4 + bx^3 + cx^2 + dx + e = 0, with known complex coefficients a, b, c, d, e. Closed form solutions exist: cubic and quartic. They look messy, indeed, but we can extract and re-use partial results, just like we substitute Δ = b^2 - 4ac in quadratic equation.

aminoxix commented 3 years ago

Yeah, it sounds good ! & may be.. this reduce our work for an instant as function.. right I agree with you.. but this functions are only applicable for Cubic, Quartic & Quintic equations, let me know if we find multiple roots from this method?

Declaration as per theory : x3 + ax2 + bx + c = 0 : Cubic equation x4 + ax3 + bx2 + cx + d = 0: Quartic equation x5 + ax4 + bx3 + cx2 + dx + e = 0 = 0: Quintic equation

TrangOul commented 3 years ago

Quintics have a form ax^5 + bx^4 + cx^3 + dx^2 + ex + f (notice the fifth power) and they do not have a general solution. The provided code solves them (and quartics) numerically. Also, you've missed terms with x in 3rd and 4th degree equations.

aminoxix commented 3 years ago

Yeah, I get your point, basically I'm dealing with quadratic in example, but we can stick with Cubic, Quartic and Quintic equation as well.. Thats great! If these functions, fulfill our needs, we like to recommend for a single button for all kinds of equations.. <3

Swastyy commented 3 years ago

@amino19 Have you created any PR for this till now?

aminoxix commented 3 years ago

@Swastyy : Nope, take it up! :slightly_smiling_face:

Meenakshi-gthub commented 2 years ago

Can I work on this issue?

aminoxix commented 2 years ago

Can I work on this issue?

If @Swastyy is not working on this issue!

Swastyy commented 2 years ago

Can I work on this issue?

If @Swastyy is not working on this issue!

There is not much work done, so @Meenakshi-gthub can start doin it.