math,floating-point,fixed-point

In decimal, your fixed-point example is actually: 2 * 4.5 2 * 45 (after multiplying by 10) = 90 90 / 10 = 9 (after dividing the 10 back out) In binary, the same thing is being done, but just with powers of 2 instead of powers of 10 (as...

http://matlabgeeks.com/tips-tutorials/floating-point-comparisons-in-matlab/ illustrated it rather well: float2bin(A) //ans = 0011111110111001100110011001100110011001100110011001100110100000 float2bin(B) //ans = 0011111110111001100110011001100110011001100110011001100110011010 You can see the difference in precision at a binary level in this example. A and B differ by 6 ulps (units in the last place)...

math,count,language-agnostic,numbers,sequence

So first you want all numbers with the digits 0 in order. i.e. just 00 Then all numbers with the digits 0,1: 00, 01, 10, 11 but excluding 00 Then all numbers with digits 0,1,2: 00, 01, 02, 10, 11, 12, 20, 21, 22 but excluding 00, 01, 10, 11...

i*i<=n is same as i<= sqrt(n) from which your iteration lasts only to order of sqrt(n). Using the straight definition of Euler totient function you are supposed to find the prime numbers that divides n. ...

while (condition) { } A while loop loops as long as the condition is true if (condition) { } else { } An if else statement continues to the else statement if the condition is falsy. In your case you have youHit = false (or equal to 0) and...

xml,xslt,math,operator-keyword,relational

First thing: you should use the namespace/s in your input XML, not dance around them with awkward expressions like *[contains(local-name(),'...')]. Now, the simplest way to exclude specific nodes is to start with the identity transform template (as you have) to copy all nodes as the rule, then add an empty...

python,math,percentage,filesize,ratio

Those sizes are integers, so Python is performing integer division. Try converting the sizes to floats first: file1Size = float(os.stat(file1).st_size) file2Size = float(os.stat(file2).st_size) In integer division, 1 / 2 is 0. But with floating pointer numbers, 1.0 / 2.0 will be 0.5....

math,javafx,geometry,coordinates

You can use the Math.atan2(dy, dx) to get the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). Later use it to convert it to degrees. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.scene.shape.Line; import javafx.stage.Stage; public class Main extends Application {...

algorithm,math,statistics,variance,standard-deviation

Given the forward formulas Mk = Mk-1 + (xk – Mk-1) / k Sk = Sk-1 + (xk – Mk-1) * (xk – Mk), it's possible to solve for Mk-1 as a function of Mk and xk and k: Mk-1 = Mk - (xk - Mk) / (k - 1)....

java,math,multiplication,string-length

It's pretty simple. Next time please show the working of your code. public int findMultiplesOf3(String value) { return (value.length()/3); } Edit Any length of the string which is less than 3 or not divisible by 3, the return value will only be a whole number. (For Ex 22/3 = 7.333...

Integer examples are for 32 bit int arithmetics, DWORD is 32bit unsigned int floating pow(x,y)=x^y is usually evaluated like this: How Math.Pow (and so on) actualy works so the fractional exponent can be evaluated: pow(x,y) = exp2(y*log2(x)) this can be done also on fixed point fixed point bignum pow integer...

math,big-o,time-complexity,asymptotic-complexity

I don't believe that the ordering you've given here is correct. Here are a few things to think about: Notice that 2log4 n = 2(log2 n / log2 4) = 2(log2 n) / 2. Can you simplify this expression? How fast does the function eπ4096 grow as a function of...

algorithm,math,recursion,time-complexity

As all the commenters said, I need to use the Akra-Bazzi theorem. C(1) = 1 C(2) = 1 For N > 2 we need to first find 'p' from the following equation : (1/3)^p + (2/3)^p = 1. It is obvious that p = 1. Next we need to solve...

You need nothing to speed up sqrt for 32-bit values. HotSpot JVM does it automatically for you. JIT compiler is smart enough to recognize f2d -> Math.sqrt() -> d2f pattern and replace it with faster sqrtss CPU instruction instead of sqrtsd. The source. The benchmark: @State(Scope.Benchmark) public class Sqrt {...

jquery,html,math,transform,velocity

The problem is that after the rotation the new target x/y values are calculated based on the rotated positions. You could buffer the target centering x/y positions of the viewport inside each slide at startup, and reuse those while animating towards the centerpoint. In this example I used jquery data...

This is combinatorics. See more information about the structure you need to understand, i.e. a permutation without repetition, also called a combination. You might be interested in combinatoricslib, a Java library on Google Code, which you could use for your program. You could also try to solve it without a...

c++,math,rotation,rotational-matrices,separating-axis-theorem

This should work whether or not polygon origin is aligned to center of gravity. I'll start with the most important stuff, and end with supporting methods that have changed. Edit: Revised implementation. struct Response { Response() : overlap(std::numeric_limits<double>::max()) {} Vector2D axis; double overlap; }; bool FindAxisLeastPenetration(const Polygon& a, const Polygon&...

I have not tested through without the source data, but you missed defining the variable pi. As for testing suggestions, personally I use oXygen for all XSL development. In pasting your template into oXygen, it immediately flagged this problem. ...

Basically, you are finding all permutations of the array using a recursive permutation algorithm. There are 4 things you need to change: First, start your loop from pos, not 0 Second, swap elements back after recursing (backtracking) Third, only test once you have generated each complete permutation (when pos =...

algorithm,math,infinite,clrs,gp

Yes, you have issues in your solution to the problem. While everything is correct in formulating the value of S, you have calculated the value of S1 incorrectly. You missed substituting the value for k=0 in S1. Whereas, for S, even after putting the value of k, the first term...

In the try block something like switch (line[0]) { case '+': num += Convert.ToInt32(line.Substring(1)); break; case '-': num -= Convert.ToInt32(line.Substring(1)); break; } where line is the current line and num is your running total. The substring will make a new string by including everything except the first character in line....

That's, actually, ok. How do you want to find the second largest \ smallest number in an array of two similar numbers? It should output "no solution" or something else. Just like there is no solution for an empty array. function SecondGreatLow(arr) { arr = noRepeat(arr).sort(function (a,b) {return a-b;}); if...

To clarify @Dan Getz and add @collapsar answer I will add the following: Dan's Formula is correct: (score1 * weight1 + ... + scoreN * weightN) / (weight1 + ... + weightN) The beauty of the weighted average is you get to choose the weights! So we choose days since...

java,math,runtime-error,println

When the decimal number is converted to binary it is approximated and not exact.So the subtraction is not exact. 3.14 is converted to binary ,so is 5 When the result reconverted to decimal it is not exact.Read about converting decimals to binary from this link : http://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm...

It's better to avoid working with slopes and angles if you can avoid them, because you will have to deal with annoying special cases like when the slope is +ve or -ve infinity and so on. If you can calculate the normal of the line (blue arrow), then you can...

java,algorithm,math,probability

Would this be ok? If you use the additive version, you'll end up having the same probabilities always. I'm using the updated multiplicative version. Also, use x<1 for lower chance of getting higher values. And x>1 otherwise. import java.util.Arrays; import java.util.Random; public class Main { private static Random random =...

python,math,numpy,matplotlib,scipy

In this case, you might be better of using Sympy, which allows you to obtain the closed form solutions: from IPython.display import display import sympy as sy from sympy.solvers.ode import dsolve import matplotlib.pyplot as plt import numpy as np sy.init_printing() # LaTeX like pretty printing for IPython t = sy.symbols("t",...

java,math,coordinates,calculator

private static final int startX = (Level.WIDTH / 2) - (Block.LENGTH * (Level.COLUMNS / 2)); This variable is evaluated once when the class it belongs to is initialized. At the time that happens, the variables it depends on (Level.WIDTH, Block.LENGTH, Level.COLUMNS) are probably still containing 0. When declaring a final...

It's different due to differences in the implementation of the functions. Neither one is perfect due to the nature of floating point. The ** operator is implemented in floatobject.c and contains a lot of special cases, but none of them are invoked here, so it ultimately reaches the standard C...

No, Html and css can not perform math operations. You can do this in javascript. But if you have choice you should not do perform complex math operations with javascript unless you know javascript well. Because javascript has some weird behaviour for example: document.write(.1 + .2) // 0.3000000000000004 (instead of...

c++,math,rotation,grid,geometry

float x_old = p.x; float y_old = p.y; p.x = x_old * cos(a) - y_old * sin(a); p.y = x_old * sin(a) + y_old * cos(a); Of course, if you are rotating many points by the same angle, you will want to save the sin & cos, instead of calculating...

I found this code on this website: <html> <head> <title>Pi</title> <script type="text/javascript"> mess = ""; Base = Math.pow(10, 11); cellSize = Math.floor(Math.log(Base) / Math.LN10); a = Number.MAX_VALUE; MaxDiv = Math.floor(Math.sqrt(a)); function makeArray(n, aX, Integer) { var i = 0; for (i = 1; i < n; i++) aX[i] = null;...

math.ceil rounds up. import math eaters = input("How many people are attending the party?") pieces = input("How many pieces will everyone eat on average?") pizzas = float(eaters) * float(pieces) orders_needed = math.ceil(pizzas/8) print(orders_needed) ...

algorithm,math,dynamic-programming

Let's take some non-decreasing sequence which qualifies, and encode it using 0s and 1s. The decoding algorithm is simple: Set the_value to 0 For each element in the coded sequence: If the element is 0, output the_value. If the element is 1, add 1 to the_value. Now, I claim that...

The number of compositions of n into k nonnegative summands is (n+k-1) choose n by the stars-and-bars method. You have k=n, so the count is 2n-1 choose n. Your examples were 3C2=3 and 5C3=10.

You can design a custom Linear Congruential Generator that generates random 5-digit numbers and is guaranteed not to repeat until it has generated all of them. An LCG generates random numbers using the following formula: Xn+1 = ((Xn * a) + c) mod m To generate 5-digit numbers m should...

I wrote a little snippet to round a number to a certain number of significant figures some time ago. You might find it useful function sigFigs(num, figures) { var delta = Math.pow(10, Math.ceil(Math.log(num) / Math.log(10)) - figures); return Math.round(num / delta) * delta; } sigFigs(number, 3); // => 8.420e+79 ...

You never reset the counter in the loop, so you only calculated the one and two values once. The other 499999 runs you re-use the same one and two counts, because the while (counter < 500) condition remains False. You can easily see the effect in the one and two...

algorithm,math,greatest-common-divisor,number-theory,clrs

That pseudocode is not Pollard-rho factorization despite the label. It is one trial of the related Brent's factorization method. In Pollard-rho factorization, in the ith step you compute x_i and x_(2i), and check the GCD of x_(2i)-x_i with n. In Brent's factorization method, you compute GCD(x_(2^a)-x_(2^a+b),n) for b=1,2, ..., 2^a....

ability to click and hover over on each Bar Unfortunately, bars don't have a pointHitDetectionRadius equivalent. But you can override the inRange function for Chart.Rectangle to give a little more vertical detection range. Chart.Rectangle.prototype.inRange = function (chartX, chartY) { return (chartX >= this.x - this.width / 2 && chartX...

What you have posted as a formula is nothing but Combination. It says that k-combination from a set of n elements is given by nCk OR n! / (k!*(n-k)!). Next, the number of combinations of n different things taken m at a time, when k particular objects occur is n-mCk-m...

python,math,combinations,itertools

Always there are 2n−1 non-empty subsets of the set {1,...,n}. For example consider the list ['a','b','c']: >>> [list(combinations(['a','b','c'],i)) for i in range(1,4)] [[('a',), ('b',), ('c',)], [('a', 'b'), ('a', 'c'), ('b', 'c')], [('a', 'b', 'c')]] >>> l=[list(combinations(['a','b','c'],i)) for i in range(1,4)] >>> sum(map(len,l)) 7 That the length of our list is...

javascript,jquery,html,angularjs,math

This is because JavaScript is taking in pr.cost as a String. It sees (pr.cost*pr.markup) and automatically converts to an integer type, but pr.cost throws it off so it adds "50"+"15" and returns "5015". This can be solved by forcing JavaScript to interpret pr.cost as an integer, an easy way being...

string,algorithm,python-2.7,math

One way of going at this would be through applications of the Jaro-Winkler String Similarity metric. Happily, this has a PyPI package. Let's start off with three string, your two examples, and the begining of your question: s1 = u''' /test/opt/somedir/blah/something def do_something(self, x): return x SomeError: do_something in 'filepath'...

Its simple maths: var res=(current-june)/current*100.0; ...

python,algorithm,math,sequence,discrete-mathematics

There are many possible solutions to this problem. Here's a reusable solution that simply decrements from 4 to 1 and adds the expected number of 1's and 0's. Loops used : 1 def sequence(n): string = "" for i in range(n): string+='1'*(n-i) string+='0'*(n-i) return string print sequence(4) There's another single-line...

Cordic is an extremely fast and efficient algorithm for implementing trigonometric functions. The most common implementations you can find refer to sin/cos functions but it can be used for their hyperbolic counterparts. Once you have an implementation for sinh/cosh is easy to get tanh. Have a look here...

java,math,2d,map-projections,mercator

As comments have pointed oit correctly, in order to precisely convert between geographic coordinates and map position, you have to know the method of projection used for the map, and a sufficient number of parameters so that tuning the remaining parameters using a suitable set of reference points becomes feasible....

arrays,matlab,math,for-loop,while-loop

In the meanSum line, you should write A(k:k+2^n-1) You want to access the elements ranging from k to k+2^n-1. Therefore you have to provide the range to the selection operation. A few suggestions: Use a search engine or a knowlegde base to gather information on the error message you received....

How about something like the following: function getAngle(y, x) { var angle = Math.atan2(-x, -y) * 180/Math.PI - 90; return angle < 0 ? 360 + angle : angle; // Ensure positive angle } ...

c,algorithm,security,math,encryption

This is not a power operator. It is the XOR operator. The thing that you notice for the XOR operator is that x ^ k ^ k == x. That means that your encryption function is already the decryption function when called with the same key and the ciphertext instead...

The code relies on the fact that: x^y == (x*x)^(y/2) The loop is doing exactly that: dividing the exponent by two while squaring the base. An example: Let's consider computing the result of 3^13. You can write the exponent (13) as a sum of binary powers: 3^(8+4+1). Then: 3^13 =...

try this: function getSmooth(meteo, usage) { meteo = Math.round(meteo*100); usage = Math.round(usage*100); return { evo: (meteo + usage) / 100, meteo: meteo / 100, usage: usage / 100 }; } to test for errors in calculations in evo separate from your visualisation logic: var evo, meteo, usage; // ... //...

another one: (A+100)*(A>-100) - 100 here the min value will be displaced to 0 to match the lower bound, then displaced back to -100....

You can use std::complex to achieve your goal, like this: #include <complex> #include <iostream> int main() { const std::complex<double> result = std::pow(std::sqrt(std::complex<double>(-36,0)), 2); std::cout << result << std::endl; std::cout << "Real part = " << result.real() << std::endl; } Output: (-36,0) Real part = -36 Note that std::sqrt(std::complex) is used...

It's called recursion, and you have a base case where f(0) == 1, so just check if (n == 0) and return 1 or recurse int f(int n) { if (n == 0) return 1; return 3 * f(n - 1) + 4; } An iterative solution is quite simple...

I having run you code and I just found you solution. in your Phpmyadmin database in side mate table cell name up_down update that, please goto Structure>up_down click Change>Attributes{UNSIGNED ZEROFILL} select that>Save And then you can test that you will find the different.

I've made a small example on this: <Window x:Class="AddTotalListConverter.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:AddTotalListConverter" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.Resources> <local:ComputationConverter x:Key="ComputationConverter"/> </Grid.Resources> <StackPanel> <ListView x:Name="lvNumbers" ItemsSource="{Binding numbers}">...

To return the nth number in the sequence, with the max number (e.g) 5 passed in: int getNum(int n, int max) { return (((n+max+1) % (max*2)) - max) * (1-((((n+max+1) / (max*2))%2)*2)); } If it's not important to start at 1, then it can be simplified to this: int getNum(int...

algorithm,math,time-complexity,computer-science,recurrence-relation

Here are a few hints : define R(n) = T(n)/(n-1)! solve the recurrence for R(n) express T(n) as a function of R(n) ...

The scale factor for the rotation mode of the circular variant of CORDIC can easily be established from first principles. The idea behind CORDIC is to take a point on the unit circle and rotate it, in steps, through the angle u whose sine and cosine we want to determine....

javascript,algorithm,math,statistics,distribution

You mention a logarithmic distribution, but it looks like your code is designed to generate a truncated geometric distribution instead, although it is flawed. There is more than one distribution called a logarithmic distribution and none of them are that common. Please clarify if you really do mean one of...

This reads each number from the input file, and outputs the correctly modified output to each output file. while IFS='' read -r number; do printf "%d\n" $((number + 5)) >&3 printf "%d\n" $((number * 5)) >&4 done < input.txt 3> first.txt 4> second.txt ...

Your C++ matrices are probably stored as row major under the hood. Which means that multiplying them from left to right is an "origin" transformation, while right to left would be a "local" incremental transformation. OpenGL however uses a column major ordering memory layout (The 13th, 14th and 15th elements...

I think you are trying to interpolate and get a vector which is a 'mix' of v1 and v2. This will be on the line between them. (Assuming v1 and v2 are treated as position vectors) You can do this by taking a weighted average of the vectors, but if...

arrays,matlab,loops,math,for-loop

If you want to get the matrices to be displayed in each column, that's going to be ugly. If I'm interpreting your request correctly, you are concatenating row vectors so that they appear as a single row. That's gonna look pretty bad. What I would suggest you do is split...

If you want to move sideways, you can simply add or subtract 90 degrees (in radians, that is π/2) from your r before calculating the sin/cos velocity vector.

The current value of evaluating the variable (expression) is passed to the method as arguments. The same happens when variable (expression) are used as operator operands1. Changing the original variables' value later - after the code has executed - has no effect on the [already complete] computation. The original expressions...

First, find the point at which the circle is touching the rectangle. You can do this by working out the angle of one of the long rectangle edges that is parallel with the line from the center of the circle to the point where it touches the rectangle. Take the...

As explained in this link, floating point numbers are not stored perfectly in computers. You are most likely experiencing some error in calculation based off of this very small difference that persists in floating point calculations. When I run your function, the equation ((x ** (1./float(z))) * 10 % 10)...

Generate the points in the straight position then apply the rotation (also check the origin of the coordinates).

The formula you provided will work. Generally speaking, for Integers >= 0 this will always be true A % B = A - [A/B] * B, where [x] denotes greatest integer <= x ...

c,math,largenumber,integer-arithmetic

The easiest thing you can do is to simply discard half of the hash and do modulo (simply using %) on the other half. The next simplest thing to do is to use an existing bignum library. If you want to use the whole hash, though, you need to do...

matlab,math,linear-programming

I'm assuming that the entries of W are positive; negative numbers don't make much sense in the context of your problem (since you're truncating at 1 and not at -1), while zeros contribute nothing and can be removed with nonzeros command. Here's how you can solve for a: Sort W...

You will need to import library visual to use the following functions. Given vector v1 and v2: To find the angle: diff_angle(v1,v2) or v1.diff_angle(v2) This gives the angle in radians. To get the dot product: dot(v1,v2) can also be written as: mag(v1)*mag(v2)*cos(diff_angle(v1,v2)) or v1.dot(v2)) To find cross product: cross(v1,v2) or:...

Each step in the CORDIC algorithm add a scaling of cos(arctan(2^-i)) (or 1/sqrt(1+2^-2i)), so for a 4 steps CORDIC, the total scaling is: cos(arctan(2^-0))*cos(arctan(2^-1))*cos(arctan(2^-2))*cos(arctan(2^-3)) = 0.60883 If you add more iterations, it gets to 0.607252935 and some. As to what to do with that factor, it's up to you and...

Devid by 10, use Math.Ceiling, and multiply by 10.

Given the parametric representation scale = 2 / (3 - cos(2*t)); x = scale * cos(t); y = scale * sin(2*t) / 2; it's quite straightforward to write the code that draws the figure. What you do is start the variable t at 0, and increment it in a loop...

Your problem is due to integer overflow when calculating -n. On your system (and my local one) INT_MIN=-2147483648 and INT_MAX=2147483647. So the problem is that -(INT_MIN) is not representable as an integer. However you can avoid this issue without going to a higher precision integer type: Since xn = xn+1...

math,factorization,number-theory

You're solving the problem from the wrong end. For any number X = p1^a1 * p2^a2 * ... * pn^an // p1..pn are prime d(X) = (a1 + 1)*(a2 + 1)* ... *(an + 1) For instance 50 = 4 * 25 = 2^2 * 5^2 d(50) = (1 +...

You can take your number that ranges from 0 to 500 and simply divide it by 500, e.g. scaled_x = x / 500.0f. Depending on the language and the type of x you will need to divide by either 500 or 500.0f. If you are using a language that has...

An example of what you can do. // assuming num will always be positive function zeroPad(num) { var str = num.toString(); if (str.length < 2) { str = "0" + str; } return str; } // assuming your time strings will always be m(m+):ss and never negative function totalTimeString(timeStrings) {...

javascript,jquery,date,math,momentjs

I would create an new array and fill in the voids, something like this var dates = []; for (var i=0; i<data.length; i++) { var now = data[i], thisStart = parseDate(now.start), thisEnd = parseDate(now.end), prevEnd = data[i-1] ? parseDate(data[i-1].end) : null; if ( prevEnd && prevEnd <= thisStart ) {...

You are considering if n is negative in the n % 2 != 0 case, but not in the else case. To make it clearer, I would handle it in a different recursive case. Take the negative n handling out of the if block, and add this line after the...

java,function,math,lambda,expression

What you need for this is currying. Given a function f which takes parameters a, b and c you can define a curried version of f which takes parameter a and spits out a function g which takes parameters b and c. Continue the currying process and you will have...

simply iterate from 1 to the maximum number of offices n and add number of required plates to total. for 1 to 9 you need 1 plate, for 10 to 99 you need 2 and so on. we implement this by using limit and step. limit indicates when we need...

The easiest way with Matlab (if you have the curve fit toolbox) is to use the cftool. This gives you a gui which you can import the data and play with the best fit. If you need to build this into a code then you can use the best function...

In psuedocode: subract the largest number from you list from your composed number,keep track of the number you started with loop that until you can't anymore move on to second largest etc start this cycle again, but start with the number smaller than the last loop you did. Not that...

You didn't provide a schema, so I worked from this: DECLARE @MeterReading TABLE( ID INT, ReadingDate DateTime, Reading MONEY) The SQL DateDiff function is the key. Given an input of an "As Of" date (that can default via GETDATE(), you can get the readings within the last month (DATEDIFF =...

Math.log(20) is base e, while LOG(20) is base 10. You're not looking for LOG(20), but probably rather LN(20) (base e). MDN (for javascript) : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log LN (for excel): https://support.office.com/en-us/article/LN-function-81fe1ed7-dac9-4acd-ba1d-07a142c6118f The LOG Function you are using automatically set the second parameter to 10 if it is not set (default 10), as...

a=1e-2 b=1e-1 midway = exp((log(a)+log(b))/2) Take the log to get the positions in log scale, then do the math. You could simplify that formula and you will end up with a geometric mean: midway=sqrt(a*b) ...

#include <cmath> // ... double angle = atan2(p2.y - p1.y, p2.x - p1.x); // ... If you want to, you can also make sure that p1 != p2, because if it is then you'll get a domain error....

Both are well defined behaviour. Quoting from http://en.cppreference.com tan If the argument is ±0, it is returned unmodified. If the argument is ±∞, NaN is returned and FE_INVALID is raised. If the argument is NaN, NaN is returned. atan If the argument is ±0, it is returned unmodified. If the...

Solving this problem requires the knowledge of three simple tricks: 1. Interpolation: The process of gradually changing from one value to another is called interpolation. There are multiple ways of interpolating color values: the simplest one is to interpolate each component linearly, i.e. in the form of: interpolated = start...

New Answer: With the change in your code you will now loop through all number. The problem with it now is that once you find a non prime number you will never reset primeEval and because of that you will never capture another prime number If you change your code...

For calculating the angle between two points use arctan(slope), where slope = (P2y - P1y) / (P2x - P1x) Where: P2y = coordinate "y" of point 2 P1y = coordinate "y" of point 1 P2x = coordinate "x" of point 2 P1x = coordinate "x" of point 1 Be aware...

p1 + p2 + ... + pn = 1 p1 = p2 * x p2 = p3 * x ... p_n-1 = pn * x Solving this gives you: p1 + p2 + ... + pn = 1 (p2 * x) + (p3 * x) + ... + (pn *...

Why not simply initializing integ to 'NONE' and remove the last test case? function integ=integerize(A) integ = 'NONE'; maxValue=max(A(:)); disp(maxValue); if maxValue <= intmax('uint8') integ='uint8'; elseif maxValue<=intmax('uint16') integ='uint16'; elseif maxValue <= intmax('uint32') integ='uint32'; elseif maxValue <= intmax('uint64') integ='uint64'; end end ...