Answered

numerical integration with recursive trapezoid rule

Some issues are immediately apparent. First, you don't reset S=0 inside the while loop. Isn't S supposed to contain only the a...

numerical integration with recursive trapezoid rule

Some issues are immediately apparent. First, you don't reset S=0 inside the while loop. Isn't S supposed to contain only the a...

3 months ago | 0

Answered

Store every N columns in a Matrix to a new Matrix

Don't create a bunch of new matrices with hard to use names downstream in your code. Instead, simply reshape your matrix and the...

Store every N columns in a Matrix to a new Matrix

Don't create a bunch of new matrices with hard to use names downstream in your code. Instead, simply reshape your matrix and the...

3 months ago | 0

| accepted

Answered

MEX file always crashes when I run it

In the MATLAB code you have this: np=single(np); Then inside the Fortran gateway routine you have this: mwPointer xr, yr, n ...

MEX file always crashes when I run it

In the MATLAB code you have this: np=single(np); Then inside the Fortran gateway routine you have this: mwPointer xr, yr, n ...

3 months ago | 0

| accepted

Answered

How can I reshape a matrix this way

a=[-0.26,0.23,0.033,0.1,-0.39,0.30;0.30,-0.39,0.10,-0.26,0.03,0.23;-0.03,-0.13,0.16,0.33,-0.16,-0.16] b=[-0.26,0.23,0.033;0.1,-...

How can I reshape a matrix this way

a=[-0.26,0.23,0.033,0.1,-0.39,0.30;0.30,-0.39,0.10,-0.26,0.03,0.23;-0.03,-0.13,0.16,0.33,-0.16,-0.16] b=[-0.26,0.23,0.033;0.1,-...

3 months ago | 0

| accepted

Answered

Matlab while loops with equations

You should probably go through the online tutorials for learning MATLAB. But I will give you an outline to get started: toleran...

Matlab while loops with equations

You should probably go through the online tutorials for learning MATLAB. But I will give you an outline to get started: toleran...

3 months ago | 0

Answered

i need to find error in code because I it's increasing but it should be decresing

You need to use all the derivatives at the first point to propagate for the initial guess at the second point. I.e., these lines...

i need to find error in code because I it's increasing but it should be decresing

You need to use all the derivatives at the first point to propagate for the initial guess at the second point. I.e., these lines...

3 months ago | 0

Answered

t = 2 s, i = √−1, and 𝜔=120π rad/s. Evaluate the following using MATLAB? Hint: exp(n) is used in MATLAB to evaluate en. (a) e−2𝑡𝑐o𝑠 (𝜔𝑡)

I am guessing that the original expression shown is supposed to be interpreted as: Then take the hint at how to evaluate the ...

t = 2 s, i = √−1, and 𝜔=120π rad/s. Evaluate the following using MATLAB? Hint: exp(n) is used in MATLAB to evaluate en. (a) e−2𝑡𝑐o𝑠 (𝜔𝑡)

I am guessing that the original expression shown is supposed to be interpreted as: Then take the hint at how to evaluate the ...

4 months ago | 0

Answered

Why is my projectile motion code only working at certain input angles.

Drag depends on current velocity, not initial velocity. So you need to recalculate V at each step. E.g., Vx = Vx_new; Vy = Vy_...

Why is my projectile motion code only working at certain input angles.

Drag depends on current velocity, not initial velocity. So you need to recalculate V at each step. E.g., Vx = Vx_new; Vy = Vy_...

4 months ago | 0

Answered

Sine equation in Euler Method ODE

You've only got one scalar differential equation, so I don't understand why you think you need two variables x and y along with ...

Sine equation in Euler Method ODE

You've only got one scalar differential equation, so I don't understand why you think you need two variables x and y along with ...

4 months ago | 0

Answered

subtract matrix from vector

Just learn how to use indexing and element-wise operators. From your language, here are the pieces: subtract - the first thre...

subtract matrix from vector

Just learn how to use indexing and element-wise operators. From your language, here are the pieces: subtract - the first thre...

4 months ago | 0

| accepted

Answered

How can I create arrays with different names using loop?

Don't embed numbering into the variable names. This will make the variables hard to use downstream in your code. Use cell arrays...

How can I create arrays with different names using loop?

Don't embed numbering into the variable names. This will make the variables hard to use downstream in your code. Use cell arrays...

4 months ago | 0

Answered

How to subtract each column of a matrix from a column vector?

Just do a usual subtraction and let MATLAB implicit expansion kick in: M = your matrix v = your column vector result = v - M;...

How to subtract each column of a matrix from a column vector?

Just do a usual subtraction and let MATLAB implicit expansion kick in: M = your matrix v = your column vector result = v - M;...

4 months ago | 0

Answered

Simple mex file crash?

You need to create the output variable yourself. plhs[0] doesn't exist until you create it, thus this line crashes: outData = m...

Simple mex file crash?

You need to create the output variable yourself. plhs[0] doesn't exist until you create it, thus this line crashes: outData = m...

5 months ago | 0

Answered

Simulating Projectile with Matlab

You don't show us both methods (with and without drag) so we can't compare them. I presume you simply set k=0 for the case witho...

Simulating Projectile with Matlab

You don't show us both methods (with and without drag) so we can't compare them. I presume you simply set k=0 for the case witho...

5 months ago | 1

| accepted

Answered

Matlab simulation for planet motion

The initial condition for position and velocity need to be outside the loop, prior to loop entry.

Matlab simulation for planet motion

The initial condition for position and velocity need to be outside the loop, prior to loop entry.

5 months ago | 1

| accepted

Answered

Vector ODE solution is not periodic/ as expected

This index 4 dxdt(4) = -DU^2* x(3)/sqrt(x(1)^2+x(2)^2+x(3)^2)^3; needs to be index 6: dxdt(6) = -DU^2* x(3)/sqrt(x(1)^2+x(2)^...

Vector ODE solution is not periodic/ as expected

This index 4 dxdt(4) = -DU^2* x(3)/sqrt(x(1)^2+x(2)^2+x(3)^2)^3; needs to be index 6: dxdt(6) = -DU^2* x(3)/sqrt(x(1)^2+x(2)^...

5 months ago | 0

| accepted

Answered

How to compile a Fortran subroutine by using the MEX engine

It looks like you are taking input, calling a MATLAB function, and getting output from that function. I still say it would be ea...

How to compile a Fortran subroutine by using the MEX engine

It looks like you are taking input, calling a MATLAB function, and getting output from that function. I still say it would be ea...

5 months ago | 0

| accepted

Answered

How to create Matrix [1 2 3 4; 2 4 6 8; 3 6 9 12; 4 8 12 16] without using loops or any functions using loops?

n = 4; % whatever result = (1:n) .* (1:n)' % use implicit expansion row .* column

How to create Matrix [1 2 3 4; 2 4 6 8; 3 6 9 12; 4 8 12 16] without using loops or any functions using loops?

n = 4; % whatever result = (1:n) .* (1:n)' % use implicit expansion row .* column

5 months ago | 2

| accepted

Answered

Vectorising Multiplying each column from a matrix with a square matrix and the tranpose of this column

If you need the same column on each side of the multiply, then maybe this: result = sum(h'*Pn.*h',2);

Vectorising Multiplying each column from a matrix with a square matrix and the tranpose of this column

If you need the same column on each side of the multiply, then maybe this: result = sum(h'*Pn.*h',2);

6 months ago | 1

Answered

Problem in using mxSetPr with USHORT

To attach pointers of type other than double to an mxArray, you can use the mxSetData( ) function as Jan suggests. In your case ...

Problem in using mxSetPr with USHORT

To attach pointers of type other than double to an mxArray, you can use the mxSetData( ) function as Jan suggests. In your case ...

6 months ago | 1

Answered

Beginner coding; my second, simpler approach at trying to make all elements distinct.

FYI, to generate random integers you can use the randi( ) function instead of ceil(value*rand( )): https://www.mathworks.com/he...

Beginner coding; my second, simpler approach at trying to make all elements distinct.

FYI, to generate random integers you can use the randi( ) function instead of ceil(value*rand( )): https://www.mathworks.com/he...

6 months ago | 0

Answered

How to make a "page transpose" in a 3D matrix without using the function pagetranspose?

Mtranspose = permute(M,[2 1 3]);

How to make a "page transpose" in a 3D matrix without using the function pagetranspose?

Mtranspose = permute(M,[2 1 3]);

6 months ago | 2

| accepted

Answered

How to multiply an inverse matrix (nxn) by an array (nx1) using for loop

Not sure why you have a for-loop at all. Maybe you can explain this. If you just want to multiply the explicit inverse by a vect...

How to multiply an inverse matrix (nxn) by an array (nx1) using for loop

Not sure why you have a for-loop at all. Maybe you can explain this. If you just want to multiply the explicit inverse by a vect...

6 months ago | 0

Answered

Adding numbers to an array

You don't really need both h and hnew. Just use h and some indexing. E.g., h = zeros(1,45); % allocate expected result k = 1; ...

Adding numbers to an array

You don't really need both h and hnew. Just use h and some indexing. E.g., h = zeros(1,45); % allocate expected result k = 1; ...

6 months ago | 0

| accepted

Answered

rounding issues in matlab, need to force values to 0

Instead of if abs(y1)< 1e-6 y1=0; end try y1(abs(y1)<1e-6) = 0;

rounding issues in matlab, need to force values to 0

Instead of if abs(y1)< 1e-6 y1=0; end try y1(abs(y1)<1e-6) = 0;

6 months ago | 2

| accepted

Answered

why will the area only work for the circle and not the other shapes

To compare strings, do not use the == operator which does an elementwise compare. Instead, use a function meant for comparing st...

why will the area only work for the circle and not the other shapes

To compare strings, do not use the == operator which does an elementwise compare. Instead, use a function meant for comparing st...

6 months ago | 0

Answered

Index exceeds number of array elements

I think you want this for i = length(t)-1 to be this instead for i = 1:length(t)-1 The way you have it currently coded, ...

Index exceeds number of array elements

I think you want this for i = length(t)-1 to be this instead for i = 1:length(t)-1 The way you have it currently coded, ...

6 months ago | 1

Answered

Calling a Matlab function in Fortran

You have two fundamental errors with this code. You do not use the correct variable type for my_x, and you cannot call mexCallMA...

Calling a Matlab function in Fortran

You have two fundamental errors with this code. You do not use the correct variable type for my_x, and you cannot call mexCallMA...

6 months ago | 0

Answered

MATLAB's inefficient copy-on-write implementation

See Loren's Blog on this topic. Basically, to write functions that can modify a variable "inplace" you need to call that functio...

MATLAB's inefficient copy-on-write implementation

See Loren's Blog on this topic. Basically, to write functions that can modify a variable "inplace" you need to call that functio...

6 months ago | 1

| accepted