Community Profile

James Tursa

Last seen: Today
3.638 total contributions since 2007

Interested in external applications, mex & engine applications with Fortran, C, C++, etc, particularly in the areas of speed improvement and memory management efficiencies.

View details...

Contributions in
View by

Finding Nonzero Elements in a Vector
You need to wrap this statement with an if-test and only execute it if v(CurrentPosition) is non-zero: prod = prod * v(CurrentP...

23 minutos ago | 0

Hint: The probability of moving from one state to another state in n steps is P^n

3 días ago | 0

Factorial without the Command
You could use either use a loop to multiply all of the numbers from 1 to n, or use recursion to multiply n by the factorial of n...

4 días ago | 0

Inputs a Vector and Returns the Second Smallest Element
Your algorithm always replaces Smallest and SecondSmallest at each iteration. Does that make sense? E.g., if the current Smalle...

4 días ago | 0

help w code error
You need to index S: f = -0.5 /(2.1+S(i));

4 días ago | 0

Hex to float like python struct.unpack()
Could be a Big Endian vs Little Endian thing. E.g., inserting a swapbytes( ) step: >> hex = 'C956F53D' hex = 'C956F53D' ...

4 días ago | 0

Python to MATLAB accuracy
Probably not. The trailing bits of floating point calculations in general can't be trusted. It you change the order of the calc...

4 días ago | 0

| accepted

solving coefficient with linear algebra
You basically have this: [ONES_COLUMN, X_COLUMN, Y_COLUMN] * p = DATA You know all the CAPS stuff. So just use the standard l...

6 días ago | 0

Composite Functions with a function with two ranges
For example, take the first one: (g o f)(x) This is just g(f(x)) which is g(x^2) Assuming we are talking only about real in...

10 días ago | 0

im trying to create a while loop for random numbers and it says if its even or odd
Change this while times < 20 to this while Ecounter < 20 and change this Ecounter = 0+1; to this ...

11 días ago | 0

The Body Mass Index, or BMI
Just get rid of these lines: function BMI=findbmi(Weight,Height)

11 días ago | 1

From where is this exp in syms calculus?
The solution space has multiple values, not just one. The solver has parameterized the solution space for you. There are multi...

18 días ago | 0

| accepted

simulate a dice throw
doc randi E.g., for a single throw you could use randi(6)

19 días ago | 1

| accepted

Why do I get "Array indices must be positive integers or logical values" error when using?
k is 3.5 So y(k-1) is y(2.5) and y(k-2) is y(1.5). The indexes are not positive integers, hence the error. Maybe you meant ...

19 días ago | 0

| accepted

How to fill mxArray with mxGetComplexDoubles?
No, this would not be expected to work. In the first place, you need to use mxDOUBLE_CLASS to create the mxArray, not mxSINGLE_...

20 días ago | 0

| accepted

The spacecraft free-fall math model

20 días ago | 0

Satellite Orbit, Friction Acceleration Function
See this link for an example that uses atmospheric drag with a satellite (in this case a satellite falling to Earth): https://w...

20 días ago | 0

Fibonacci Series Using Recursive Function
All of your recursive calls decrement n-1. Eventually you will wind up with the input n=0 and just return v=0, which is not wha...

21 días ago | 0

How to fix error: "Index in position 1 is invalid. Array indices must be positive integers or logical values"
Type the following at the command line: dbstop if error Then run your code. When the error occurs, the code will pause with a...

23 días ago | 0

| accepted

Why do I get this error message "Array indices must be positive integers or logical values."
You forgot to multiply between the y and (y-1) Z = x(:).^2.*y.*(y-1).*(y+1); Also, make sure to use element-wise operators (wi...

24 días ago | 0

pointers in object-oriented matlab programing
MATLAB does not have variable pointers ... at least not in the sense of C/C++ like you are probably alluding to.

25 días ago | 0

Recursion in matrix calculation
This uses recursive calls (CalDet calls CalDet with smaller matrices until the size is 1x1). I.e., the recursion continues all ...

26 días ago | 1

How C++ gets struct values from Matlab
Looks like your strings are char type and not the newer string type. So you can try the following: mxArray *mx; char *name; ...

26 días ago | 0

Checking whether two complex matrices are equal
You can't rely on floating point calculations to give exact results. See this link: https://ch.mathworks.com/matlabcentral/ans...

27 días ago | 2

| accepted

IMU orientation using AHRS filter
I haven't used either of those functions, but from reading the doc maybe you need to use the conjugate of the quaternions in you...

28 días ago | 1

Quick way to Invert the matrix (A+D) where the inverse of matrix A is known and the matrix D is diagonal.
Are the values in D small compared to A^-1 ? Maybe you can make use of one of the forms listed here: https://en.wikipedia.org/...

alrededor de 1 mes ago | 0

How do I program the orbit of a particle that is experiencing Gravity & Radiation Force Pressure?
The differential equation is simply Newton's F = ma, where m is the mass of the object (M1) and a is the acceleration of the obj...

alrededor de 1 mes ago | 0

Numerical integration RK4 for the given data
E.g., a VERY SIMPLISTIC approach showing one step of Euler integration dt = some delta time value q = [1,0,0,0]; % Initial qua...

alrededor de 1 mes ago | 0

| accepted

How to convert this 2D code segment with random number into the FORTRAN code?
For your particular case, looks like the MATLAB code could reduce to: Nx = 4; Ny = 4; c1 = 0.12; rr = 0.0001; D = c1 + rr*(...

alrededor de 1 mes ago | 1