Answered

Error using vertcat Dimensions of arrays being concatenated are not consistent.

You have a mismatch in the number of arguments. E.g., this [V,y] = ode45(@(~,y) fun(del_h1,del_cp1,cp1),Vspan,y0); should be ...

Error using vertcat Dimensions of arrays being concatenated are not consistent.

You have a mismatch in the number of arguments. E.g., this [V,y] = ode45(@(~,y) fun(del_h1,del_cp1,cp1),Vspan,y0); should be ...

6 months ago | 0

Answered

Replacing matrix n column values

E.g., temp = A(:,70:80); temp(temp<0) = 0; A(:,70:80) = temp;

Replacing matrix n column values

E.g., temp = A(:,70:80); temp(temp<0) = 0; A(:,70:80) = temp;

6 months ago | 1

| accepted

Answered

Solving an overdetermined system of linear equations

Since you can simply plug in those values to verify that they satisfy all four equations, the conclusion would be that you have ...

Solving an overdetermined system of linear equations

Since you can simply plug in those values to verify that they satisfy all four equations, the conclusion would be that you have ...

6 months ago | 0

| accepted

Answered

How to create a cell array with binary numbers?

Your pop variable has 1000x11 = 11000 elements. Your for-loop only assigns values to 1000 of those elements (the first column)....

How to create a cell array with binary numbers?

Your pop variable has 1000x11 = 11000 elements. Your for-loop only assigns values to 1000 of those elements (the first column)....

6 months ago | 0

Answered

invalid use of operator

You are missing a ( after the second "if", and you are missing an "end" statement. That being said, my suggestion would be to u...

invalid use of operator

You are missing a ( after the second "if", and you are missing an "end" statement. That being said, my suggestion would be to u...

6 months ago | 0

Answered

Need Help Solving Two Coupled ODEs

The derivative function needs to have the input arguments specified. In your current code above, you have no inputs specified. ...

Need Help Solving Two Coupled ODEs

The derivative function needs to have the input arguments specified. In your current code above, you have no inputs specified. ...

6 months ago | 0

| accepted

Answered

Versions of Euler Methods

methodA has a fundamental flaw: y(i+1) = y(i)+ h*func( t(i) + h/2, (y(i)+y(i+1))/2 ); You can't use y(i+1) on the right hand s...

Versions of Euler Methods

methodA has a fundamental flaw: y(i+1) = y(i)+ h*func( t(i) + h/2, (y(i)+y(i+1))/2 ); You can't use y(i+1) on the right hand s...

6 months ago | 1

Answered

Problem with matrix differential equation resolve in Matlab with ode45

Normally I would have expected ode45( ) to pass q as a 4x1 column vector. Also, I don't see anything in your code solving for q...

Problem with matrix differential equation resolve in Matlab with ode45

Normally I would have expected ode45( ) to pass q as a 4x1 column vector. Also, I don't see anything in your code solving for q...

6 months ago | 0

| accepted

Answered

Question regarding quaternion conventions; particularly with respect to point vs frame rotations

See this post for comments regarding "point" vs "frame" convention: https://www.mathworks.com/matlabcentral/answers/524471-what...

Question regarding quaternion conventions; particularly with respect to point vs frame rotations

See this post for comments regarding "point" vs "frame" convention: https://www.mathworks.com/matlabcentral/answers/524471-what...

6 months ago | 0

Answered

Using vectorization to shorten run time

E.g., [P,D] = meshgrid(p,d); % generate all possible combinations X = [P(:) D(:)]; % combine them into side-by-side column vec...

Using vectorization to shorten run time

E.g., [P,D] = meshgrid(p,d); % generate all possible combinations X = [P(:) D(:)]; % combine them into side-by-side column vec...

6 months ago | 1

| accepted

Answered

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...

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...

6 months ago | 1

| accepted

Answered

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...

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...

6 months ago | 0

Answered

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...

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...

6 months ago | 0

Answered

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'),:);

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'),:);

6 months ago | 0

| accepted

Answered

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...

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...

6 months ago | 0

| accepted

Answered

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 ...

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 ...

6 months ago | 1

Answered

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...

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...

6 months ago | 0

| accepted

Answered

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...

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...

6 months ago | 0

Answered

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...

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...

6 months ago | 0

Answered

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...

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...

7 months ago | 0

Answered

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...

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...

7 months ago | 0

Answered

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?

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?

7 months ago | 0

| accepted

Answered

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...

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...

7 months ago | 1

| accepted

Answered

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...

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...

7 months ago | 0

Answered

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. ...

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. ...

7 months ago | 0

Answered

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...

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...

7 months ago | 1

| accepted

Answered

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...

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...

7 months ago | 0

| accepted

Answered

"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; ...

"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; ...

7 months ago | 0

Answered

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...

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...

7 months ago | 0