Answered
How to compare elements of two vectors in MATLAB ?
Compare for what purpose? E.g., these statements will compare them: isequal(v1,v2) % are they equal v1 == v2 % matrix of indi...

3 years ago | 0

Answered
Problem with time steps in Runge-Kutte method
"... I get different results with different time steps ..." In general, that is the expected result. I suppose the real questi...

3 years ago | 1

Answered
angle2dcm: How to reference direction cosine matrix output?
Does this do what you want: x = zeros(1,m); % reorder these to row vectors y = zeros(1,m); z = zeros(1,m); : xyz = [x;y;z];...

3 years ago | 0

| accepted

Answered
Motion equation of a space engin in low earth orbit
As Bjorn has pointed out, your J2 terms are all the same but they should be different because the equatorial bulge affects the z...

3 years ago | 1

Answered
Problem using 4th order Runge-Kutta method
You have a factor of 2*K4 that shouldn't be there. It should just be K4. E.g., Fx = @(t,x,vx,y,vy,z,vz) [vx; 3*t; vy; t; vz; 7*...

3 years ago | 0

Answered
How can I find angle between two vectors in 3D ranging from 0 to 360 or -180 to +180?
https://www.mathworks.com/matlabcentral/answers/501449-angle-betwen-two-3d-vectors-in-the-range-0-360-degree

3 years ago | 0

Answered
Add another column to the right end of this array
your_matrix(:,end+1) = 1.5;

3 years ago | 0

Answered
Convert Number Character array to Number Integer array/matrix?
Numeric types typically do not get displayed with leading 0's. The numbers you show are converted correctly, they just don't pr...

3 years ago | 0

Answered
Use strcpy with mxArrayToString ?
char* inputStr2 = strcpy(inputStr2, inputStr); % Not working and causing matlab to crash This line crashes because inputStr2 is...

3 years ago | 1

| accepted

Answered
How to find the number of non-NaN elements in a column that are NaN in the last column, in MatLab?
Code is written from a slightly reordered wording: "for each column, number of elements that are NaN in the last column and non...

3 years ago | 0

| accepted

Answered
How to call function repeatedly using arrays as variables?
There are other ways do to this, but to answer your question about how to turn the code into a loop, use indexing based on the n...

3 years ago | 1

| accepted

Answered
Best Practice: Many Functions relying on Global Variables?
See this link for a related discussion involving the best way to define global constants, in particular Steven Lord's answer: h...

3 years ago | 1

| accepted

Answered
Use Matlab to find the acceleration and jerk of the body with velocity
Take the derivative of velocity to get acceleration. Take the derivative of acceleration to get jerk. Since you have an explic...

3 years ago | 0

Answered
floating-point arithmetic
"... the IEEE754 conversion of 0.1234 and 0.123 have infinite digits ..." Not sure what you mean by this statement. Neither of ...

3 years ago | 0

Answered
random number generating RANDI with percentage
One way: n = 1000; p = 0.86; r = rand(n,1); x = r < p; m = sum(x); r(x) = randi([0,14],m,1); r(~x) = randi([15,28],n-m,1)...

3 years ago | 0

Answered
Points inside the sphere
Just plug your points into the ellipsoid equation and see if they work. E.g., ((x - X)/a).^2 + ((y - Y)/b).^2 + ((z - Z)/c).^2 ...

3 years ago | 1

| accepted

Answered
Strange output from symbolic calculation
This isn't strange at all. You are asking the Symbolic Engine to examine all floating point expressions involving pi, which isn'...

3 years ago | 0

Answered
I keep getting an error?
Generally, these types of problems are solved by extracting the contents of the cell instead of using the cell itself. E.g., C ...

3 years ago | 0

Answered
3D sparse matrices
You can use the ndSparse FEX submission by Matt J: https://www.mathworks.com/matlabcentral/fileexchange/29832-n-dimensional-spa...

3 years ago | 0

Answered
Convert Fortran to MATLAB
Here is the equivalent MATLAB code: NB = 100; F = 0; for i=1:NB % [some equations] if( abs(xm) < wm ) ym ...

3 years ago | 0

| accepted

Answered
What is the difference between a^3 and a.^3 if a is a matrix?
E = C^3 is a matrix power, equivalent to E = C*C*C, where these are all matrix multiplies. D = C.^3 is element-wise power, wher...

3 years ago | 2

| accepted

Answered
Need Help for the rest of this coding
This is very basic vector construction and indexing. I suggest you take the MATLAB Onramp tutorials found here: https://www.mat...

3 years ago | 0

Answered
Malfunction to my matrix calculation
K .* F (with the dot) does element-wise multiplication with implicit array expansion if the variables are different sizes, thus ...

3 years ago | 1

| accepted

Answered
How do I write this c++ for loop statement in Matlab for loop?
E.g., using a while loop (changed max and min to maxx and minn): x = j; while( maxx >= minn && x <= m+r ) % body of loop ...

3 years ago | 0

| accepted

Answered
why my matlab code calculates the inequality wrongly?
Negative numbers are not greater than positive numbers. This is the correct result. What is strange to you about this?

3 years ago | 0

| accepted

Answered
RK4 Method for Windkessel error
Multiple errors. When you call your function handle f, it is assumed that the P and Q are values passed at time t. They are not ...

3 years ago | 1

| accepted

Answered
Use a for loop to determine the sum of the first ten even terms in the series 5k3 (k=2, 4, 6, ….)
You are summing all the terms with 2:10. For the "even" terms you need to skip the odd ones, so the range would be 2:2:something...

3 years ago | 0

Answered
Polt an object in uniform circular motion with Euler method
So you have made a good start, but you have errors in your derivatives ... why do you have t's in your derivative equations? The...

3 years ago | 0

Answered
How to solve a non-linear system of differential equations?
Your equations are linear in the derivatives, so you can form your equations as a matrix equation, then write a derivative funct...

3 years ago | 1

| accepted

Answered
What do I need to change to get my Improved Euler's to match my Euler's?
Your current code is hard to read and debug because you have multiple variations of this expression scattered throughout your co...

3 years ago | 0

Load more