Community Profile

# James Tursa

##### Last seen: Today
3,280 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.

#### James Tursa's Badges

View details...

Contributions in
View by

Image read in MATLAB and C
An int is likely 4 bytes on your machine, not 2 bytes. Also the expression "order" by itself evaluates as a pointer to the firs...

3 days ago | 0

Appending a row vector into a matrix based on given conditions
x = abs(b-60) > abs(b-550); % fixed typo xzplane550 = equakemat(x,:); xzplane60 = equakemat(~x,:); If all the data ends up in...

3 days ago | 0

| accepted

Is it a mistake that the function sum?
Welcome to the world of floating point arithmetic. https://www.mathworks.com/matlabcentral/answers/57444-faq-why-is-0-3-0-2-0-1...

4 days ago | 1

return any angle to (0 to 2pi) range
The short answer: mod(x,2*pi) The long answer for this particular mod operation, is that if you want to get the same answer fo...

5 days ago | 0

| accepted

Precision quandaries: why can I print 64 digits?
What you describe sounds like it is just a display issue. Earlier versions of MATLAB on PC machines used a library print functi...

5 days ago | 0

| accepted

Grabbing number from array to calculate the numerical derivative
For the version you post, see the diff( ) function along with element-wise divide. E.g., diff(y) ./ diff(x) If that doesn't wo...

6 days ago | 0

| accepted

Coding a quadratic root finder
I would advise having your logic figure out what situation you have before you start solving things. E.g., something like if( a...

6 days ago | 0

Numerical solution of ODEs system using ODE45
You've got a 2nd order DE and a 3rd order DE, so the order of your system is 2+3=5, not 6. So your state vector should have 5 e...

7 days ago | 1

Am I doing this right? (a Math formula to Matlab language)
You are on the right track, but have typos in the code due to parentheses issues. A = sum( (x - y).^2 ); B = sum( (x - mean(x)...

8 days ago | 1

| accepted

Numerical solution of Higher order differential equation using ODE45 and a m. archice
t is a number, not a symbol. So u = sin(t) is a number, not a symbolic function. So doing diff(u) does diff on a single value,...

8 days ago | 0

| accepted

Write an executable script file (m-file) that takes no inputs and returns the displacement and stored energy of a spring system after prompting the user for the 1) input forces (in N) on the spring and 2) the spring constant (in N/m).
To get you started, simply create an m-file with something like this at the front end: F = input('Input the force on the spring...

10 days ago | 0

| accepted

How can I add 1 to a particular element in a matrix?
M = your 13x13 matrix M(1,2) = M(1,2) + 1;

10 days ago | 0

| accepted

How to determine Simplex using Nelder-Mead Algorithm in all direction?
The Nelder-Mead Simplex Method is an adaptive method that adjusts the lengths and directions dynamically. The vertices could be ...

11 days ago | 0

Question on why tilde cannot return the opposite statement result
Precedence of ~ is hgher than >, so it gets performed first. You need to use parentheses: ~(adultdata.age>50)

11 days ago | 0

| accepted

A single column vector or an array, which is faster?
Other things you are doing in your code are likely to dominate run times. We would need to see your particular application to of...

12 days ago | 0

| accepted

Matrices and indexing ?!
[LX,LY] = ndgrid(Lx,Ly); z = LX(:)./LY(:) <= 2; LX = LX(z); LY = LY(z); LX and LY contain the number pairs that match the co...

12 days ago | 0

Sort rows of matrix by matching column with another matrix column
E.g., assuming everything in column 31 has a match [~,x] = ismember(A(:,31),B(:,31)); Bsort = B(x,:);

13 days ago | 1

| accepted

how to find max value of a function with a for loop
Make e a vector. E.g., for i=1:length(x) e(i) = y(i) - (m*x(i)-b); % <-- Are you sure that isn't supposed to be (m*x(i) +...

13 days ago | 1

| accepted

How to solve a system of ODEs and plot the result
This is where you needed to show us the complete code and the complete error message. It is probably complaining about your init...

13 days ago | 0

| accepted

precision of calculation with Matlab
Calculators may not use the same floating point representations or arithmetic routines that MATLAB uses, so differences in the t...

13 days ago | 0

How to code for this equation in Matlab
Assuming that f(x) is really supposed to be f(t): f = @(t)exp(j*w*t); But, you will need to have w defined prior to this.

13 days ago | 0

| accepted

Mex C file generation Linker library error
Do you already have a zzz.lib file? Normally to get your mexFunction code to link to the library you simply include it as part ...

13 days ago | 0

| accepted

rand command give different answer
rand( ) is a random number generator ... it is supposed to give a different result. doc rand If you want to start over with th...

14 days ago | 1

Help creating an array to hold approx error from a taylor series
Generally, just index into your variable inside the loop: a_values(index) = a_err; If the indexing could be large, you would a...

16 days ago | 0

What is the Aerospace Blockset quaternion convention?

17 days ago | 0

angle between three points (in 3D)?
See the discussion in these links: https://www.mathworks.com/matlabcentral/answers/101590-how-can-i-determine-the-angle-between...

17 days ago | 0

How to convert char to uint8 and vice versa without changing the underlying data
Simply: c = original char array u = uint8(c); Or u = original uint8 array c = char(u); If you mean you want to reinterpret...

19 days ago | 0

Multiplying each column of a matrix with a specific value
mat=[2,1,0,0;1,0,0,0;0,0,0,1]; % 2D matrix f = [25,5,10,1]; % row vector result = f .* mat; % element-wise multiply with virtu...

19 days ago | 0

| accepted