Risposto
why does dimension of input variable change in ode45
The dimension changes to a column vector because that is the way ode45( ) operates. Your derivative function needs to be able t...

oltre 5 anni fa | 1

| accettato

Risposto
Maatlab crash with .mex function
I had to make some assumptions about how the matrix data areas are supposed to be loaded. We can try this first to see if these...

oltre 5 anni fa | 0

Risposto
How to calculate standard deviation in double for loop?
The short answer is don't do that. This style of programming has many problems. See this link for alternatives: https://www.m...

oltre 5 anni fa | 0

Risposto
Add row to an empty array if a condition is fulfilled
No need for an explicit loop. Just use logical indexing: result = m(strcmp(m(:,3),'A'),:);

oltre 5 anni fa | 0

| accettato

Risposto
reproduce random numbers for the third dimension
If you don't want the random numbers to change from iteration to iteration, then don't regenerate them inside the loop. Calcula...

oltre 5 anni fa | 0

| accettato

Risposto
Using an Array as an input
The error message actually tells you exactly what to do. Use element-wise operator .^ instead of the matrix operator ^ Energy ...

oltre 5 anni fa | 1

Risposto
Runge-Kutta 2
The + 4.*x1 should be - 4.*x1 in your derivative function. Also, using both X1 and x1 and X2 and x2, even though MATLAB is case...

oltre 5 anni fa | 0

| accettato

Risposto
3D array of rotation matrices multiplied on 2D array of vectors
To answer your side question of how to transpose 2D pages of an array, you can use the permute function to swap the first two di...

oltre 5 anni fa | 0

Risposto
Passing structs/objects to functions
MATLAB typically passes shared data copies of input arguments to functions. That means creating a separate mxArray header for t...

oltre 5 anni fa | 0

Risposto
How can I solve a system of ODE's, in which the equations have a dependency on time, as well as the other ODEs?
Just code it up as it appears using a 3-element state vector, where the elements are defined as follows y(1) = x y(2) = y y(3...

oltre 5 anni fa | 0

Risposto
How to improve the speed of large matrix addition?
If you are generating a new matrix C each time, then you are essentially doing two things: (1) Copying all the elements of A in...

oltre 5 anni fa | 0

Risposto
Dealing with very small or very large numbers
I guess the obvious suggestion is to work in units of nanometers or maybe picometers instead of meters. Can you do that?

oltre 5 anni fa | 0

| accettato

Risposto
How to use if statement in function?
Add this code to the top of your function: if( N <= 0 ) error('N needs to be > 0') end That being said, your loop probab...

oltre 5 anni fa | 1

| accettato

Risposto
How to build a quaternion from a normal vector?
If you have the Aerospace Toolbox, you could do the following n = 1x3 unit normal vector a = angle to rotate in radians v = 1...

oltre 5 anni fa | 0

Risposto
Runge-Kutta 2
Normally one would plot the position, not the velocity. So I would have expected you to plot the "1" index of your solutions. ...

oltre 5 anni fa | 0

Risposto
Double Variable Second order Differential Equation
Just write a derivative function using four states instead of two. The states will be x, y, dxdt, and dydt. The derivitives of...

oltre 5 anni fa | 1

| accettato

Risposto
How can I divide each element of a vector by each of the elements of another vector in MATLAB?
Assuming a and b are both column vectors, you can use automatic array expansion by transposing one of them and using element-wis...

oltre 5 anni fa | 0

| accettato

Risposto
"Array indicies must be positive integers" error
You can't have 0 or fractional indexing in MATLAB. Take this section of code for example: for t = 0:1:200 U(0,t) = ui; ...

oltre 5 anni fa | 0

Risposto
what is the difference between the 2 codes ?
zeros([2,2]) passes one argument, a 2-element vector [2,2]. zeros(2,2) passes two arguments, the scalars 2 and 2. The result i...

oltre 5 anni fa | 0

Risposto
Getting all Permutations of a 18+ integer vector
The number of different permutations of a vector of size n is n! (n factorial). So what you are attempting has these many possi...

oltre 5 anni fa | 0

Risposto
Calculating a matrix with a specific form
You could rearrange the equations, isolate m(1), m(2), and m(3) and solve for them directly. E.g., rearrange the equations to f...

oltre 5 anni fa | 2

Risposto
Combine logical arrays into one array
L = L1 | L2 | L3 | L4;

oltre 5 anni fa | 1

| accettato

Risposto
How to vectorise code involving matrix multiplications with vectors
See this link: https://www.mathworks.com/matlabcentral/answers/776812-how-to-vectorize-a-b-operation-on-slices-of-3d-matrices?s...

oltre 5 anni fa | 0

| accettato

Risposto
What is the corect code for writing an error message when a user inputs an array instead of a scalar value?
Several ways to test for a scalar. E.g., if( ~isscalar(x) ) error('Input is not a scalar'); end or if( numel(x) ~= 1 )...

oltre 5 anni fa | 1

Risposto
Calculating and and recording a vector during each iteration of a "while" loop.
E.g., using a counter to store all of your iteration data in a cell array and then post process this: k = 1; % the counter Rce...

oltre 5 anni fa | 0

| accettato

Risposto
Trying to separate Quaternion coefficients into array.
Use the double( ) function to convert to numeric array, then use regular indexing. E.g., try this function g = actfun(q) ...

oltre 5 anni fa | 1

| accettato

Risposto
quat2eul is giving me a strange result
Maybe all you have to do is add 2*pi to all results that are less than -pi to get things how you want.

oltre 5 anni fa | 0

| accettato

Risposto
Handling Inputs mex function
The prhs[ ] variables are of type pointer to mxArray ... you cannot use simple native C conversions with them. You must use som...

oltre 5 anni fa | 1

| accettato

Risposto
How can I fix this error?
Delete the extra closing parentheses. I.e., delete the paren where the red underline is.

oltre 5 anni fa | 0

Risposto
Undefined function or variable t
Put this code in a separate file called Math.m % file Math.m function dxdt=Math(t,x1) % function name x=x1(1) y=x1(2) z=x1(...

oltre 5 anni fa | 0

Carica altro