[Solved] How to solve this equation [closed]

You can use sympy, Python’s symbolic math library. from sympy import solve from sympy.abc import C print(solve(1298 + 74.86 * C + 1.283 * C ** 2 – .0078 * C ** 3 – .0006 * C ** 4)) # result: [-28.2719434096994, 62.3383358961427, -23.5331962432216 – 25.9550273611766*I, -23.5331962432216 + 25.9550273611766*I] 0 solved How to solve this … Read more

[Solved] How to calculate shortest distance from path?

Mathematically : As explained in wikipedia the shortest distance between a line and a dot, can be calculated as follows: If the line passes through two points P1=(x1,y1) and P2=(x2,y2) then the distance of (x0,y0) from the line is: Java implimentaion class Point { double x,y; Point(double pX, double pY){ this.x= pX; this.y= pY; } … Read more

[Solved] Sum a number with divisors to get another number

You can solve this using dynamic programming #include <iostream> using namespace std; #define INF 1000000007 int main() { // your code goes here int dp[101] = {0}; int a,b,i,j; scanf(“%d%d”,&a, &b); for(i=a;i<=b;i++) dp[i] = INF; dp[a] = 0; for(i=a; i<=b; i++){ for(j=2; j*j<=i; j++){ if(i%j == 0){ dp[i+j] = min(dp[i+j], dp[i]+1); dp[i+i/j] = min(dp[i+i/j], dp[i]+1); … Read more

[Solved] How to add the sum of ints n to c [closed]

You can do it by using a loop and from what I understand, a seperate method, which we’ll call addSum. In addSum, we will create a for loop with the starting limits and the ending limit. public static void addSum(int start, int end) { int addMe = 0; for(; start <= end; start++) { addMe … Read more

[Solved] Three type of Balls from Bag

If K>max(R,G,B) then the problem has no solution. So let’s assume K <= max(R,G,B). If you don’t have any control over which ball gets extracted, you’ll need at most (i.e. this is a lower bound) min(R, (K-1))+min(G, (K-1))+min(B, (K-1))+1 extractions for obvious reasons: extract K-1 red balls (or all red balls if R<K), then extract … Read more

[Solved] Testing a quadratic equation

Not sure what trouble you’re having. I wrote: public class Quad { public static void main(String[] args) { double a = Double.parseDouble(args[0]); double b = Double.parseDouble(args[1]); System.out.println(Math.abs(b/a – 200.0)); if (Math.abs(b/a – 200.0) < 1.0e-4) { System.out.println(“first one”); } else { System.out.println(“second one”); } } } And some output: animato:~/src/Java/SO$ java Quad 1 200 0.0 … Read more

[Solved] What is the shortest way to calculate running median in python?

This is the shortest: from scipy.ndimage import median_filter values = [1,1,1,0,1,1,1,1,1,1,1,2,1,1,1,10,1,1,1,1,1,1,1,1,1,1,0,1] print median_filter(values, 7, mode=”mirror”) and it works correctly in the edges (or you can choose how it works at the edges). And any general running X is done like this (running standard deviation as an example): import numpy from scipy.ndimage.filters import generic_filter values = … Read more

[Solved] Error using Math.pow and Math.sqrt in Java [closed]

v_y = 51 – time*3; v = (int)Math.pow(v_y+20, 2); v_squart = (int)Math.sqrt(v); // why take the square root of something you just squared… height = 456 – v; System.out.print(“The height of the plane is” + height); Integers cannot contain decimal values, Math.pow and Math.sqrt both return double types. You have declared v_y, v and v_squart … Read more

[Solved] How can I get the sum, difference, quotient, product of two values and printed out in textview [closed]

add two EditText for getting two numbers then add four button for different operation like add/sub/mul/div. Get value of editText and Set onClickListener and write appropriate code in that. EditText firstNumber; EditText secondNumber; TextView addResult; Button btnAdd; double num1,num2,sum; firstNumber = (EditText)findViewById(R.id.txtNumber1); secondNumber = (EditText)findViewById(R.id.txtNumber2); addResult = (TextView)findViewById(R.id.txtResult); btnAdd = (Button)findViewById(R.id.btnAdd); btnAdd.setOnClickListener(new OnClickListener() { public … Read more

[Solved] Given 1 < a < 10, 1 ≤ n ≤ 100000, show how to compute the value of 1 × a + 2 × a^2 + 3 × a^3 + . . . + n × a^n efficiently, i.e. in O(log n)!

If this is homework I guess your professor explained you how to compute Fibonnacci numbers and expect you to use the same trick. So basically remark that: |1+a+ a²+…+ a^n| |a 0 1| |1+a+ a²+…+ a^(n-1)| | a+2a²+…+na^n| = |a a 1| | a+2a²+…+(n-1)a^(n-1)| |1 | |0 0 1| |1 | |a 0 1|^n |1| … Read more