Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 375129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:28:21+00:00 2026-05-12T14:28:21+00:00

I have a function to calculate the inverse of a quadratic equation. By default

  • 0

I have a function to calculate the inverse of a quadratic equation. By default it gives the two possible solutions:

invquad<-function(a,b,c,y,roots="both")
{
    #Calculate the inverse of a quadratic function y=ax^2+bx+c (i.e. find x when given y.)
    #Gives NaN with non real solutions.
    root1<-sqrt((y-(c-b^2/(4*a)))/a)-(b/(2*a))
    root2<--sqrt((y-(c-b^2/(4*a)))/a)-(b/(2*a))
    if (roots=="both")
        result<-c(root1,root2)
    if (roots=="min")
        result<-min(root1,root2)
    if (roots=="max")
        result<-max(root1,root2)
    result
}

This works fine if given a single value of y, but if I give it a list or a column from a dataframe, then the min and max elements give me the minimum value of the whole list. I want it to return just the minimum result for that element. I’m assuming iterating over the list is possible, but it is not very efficient.

Any ideas ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:28:21+00:00Added an answer on May 12, 2026 at 2:28 pm

    Replace the min (max) function by pmin (pmax):

    > invquad(1,2,3,3,"min")
    [1] -2
    > invquad(1,2,3,4,"min")
    [1] -2.414214
    > invquad(1,2,3,c(3,4),"min")
    [1] -2.000000 -2.414214
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two PHP functions to calculate the relation between two texts. They both
I have a model which have a function to calculate the difference between two
Here I have a function which I use to calculate the difference between two
I have a function which calculate the difference between two timestamps, public static function
I have a function to calculate the difference between two dates. function getDateDifference($to, $from,
i have a function to calculate several different values: int ASPfile::get_dimensions(int* Lat, int* Lon,
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1
I am using jQuery(Latest release) and have a function called calculate() which gets called
I have a function in PHP which calculates the distance between two places. Here
I wanted to calculate the angle between two vectors but I have seen these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.