Creating Unit vectors in a loop
Since a complete answer has already been posted, I will post this one using a cell array result which will be much easier to ind...

21 days ago | 1

When i run this code i get error using dec2bin (too many input arguments).
MATLAB is case sensitive. Text (uppercase T) is different from text (lowercase t). In the future, please post the complete erro...

21 days ago | 0

Maclauren Series Iteration. Answer provided just having trouble getting code to run properly
Some issues: 1) This line: new_cos=(old_cos-(x^n))/(factorial(n)); You are dividing the old_cos by the factorial(n). This do...

21 days ago | 1

| accepted

Model a simple circular satellite orbit in time
Since you are setting up a circular orbit, just scale the time by the period to get theta. E.g., since one period would be an an...

22 days ago | 0

| accepted

Question: Create a function that takes a generic matrix, x, and finds the smallest value in the matrix.The function must work for matrices of any size and dimension.
Hint: First reshape the input x array into a 1D vector and work with that inside your function.

24 days ago | 1

| accepted

How to wrap on overflow when transfer a double to integer
You could use: y = mod(x,double(intmax('uint16'))+1); But, if x is too large so that eps(x) > 1 the result might be somewhat m...

25 days ago | 1

| accepted

Finding all multiples of 5 or 7 from 1 to 10000 with a loop.
An basic outline of the for loop to get you started: n = 10000; % the limit of the for loop x57a = []; % initialize the result...

25 days ago | 0

What type of function Matlab has help to construct symmetric matrix?
If no specific properties needed, then you could use n = the desired size M = rand(n); M = M + M';

26 days ago | 1

Matrix dimensions must agree error in FOR loop
This comparison: z == 'no' compares z to a 1x2 array. And this comparison z == 'yes' compares z to a 1x3 array. So you are...

26 days ago | 0

Calling C functions using MATLAB.
This: void (*camp)(double x, double *y, int n, double *f) is not a function as you claim. It is a pointer to a function that ...

26 days ago | 0

Can't figure out what I am doing wrong. Looking to find square root using the equation given x=(x+x/a)/2. I also feel like I am not making use of the approximation errors ea and es.
You can't do these assignments in this order: x_old=x; ea=((x-x_old)/x)*100; The first one will cause the second one ...

27 days ago | 1

Coupled second order ODE with three variables
Problems: 1) Units. You really should annotate ALL of your constants with descriptions and units so that the reader knows what...

28 days ago | 0

How to split 3d matrix into sub-2d matrices?
I agree with Bob ... just using indexing downstream in your code will be much easier. If you really do need them in separate va...

28 days ago | 1

ODE45 to solve vector ode
You have a six element state vector. The y(1) and y(2) coming into your derivative function are not position and velocity vecto...

1 month ago | 1

| accepted

code in script called swap
You can adapt the three lines of code found here: https://www.tutorialspoint.com/learn_c_by_examples/swapping_two_numbers_using...

1 month ago | 0

Extract values common to 5 columns
Hint: Look at the result of diff(A,[],2). If all the values in a row are equal, what would you expect to be in the result of th...

1 month ago | 0

Element-wise power resulting in imaginary values and NAN
Looks like the problem calculation is being done in the background as exp(B.*log(A)), but I don't know why it does this sometime...

1 month ago | 0

| accepted

How to make a loop that writes in a new vector only values that meet a condition?
Assuming you don't want the first value since there is no previous value to compare to: x = [false, diff(VPo) > 0]; VPoF = VPo...

1 month ago | 0

| accepted

Out of Memory error when removing columns of a big matrix .
What are you doing with the matrix A downstream in your code? Even if the column removal worked, seems like you still might hav...

1 month ago | 0

Choose random element of vector
k = sort(randperm(numel(vector),2)); x1 = vector(k(1)); x2 = vector(k(2)); This assumes that you always want to be able to pi...

1 month ago | 1

Angle betwen two 3d vectors in the range 0-360 degree
E.g., here is one method: function a = vecangle360(v1,v2,n) x = cross(v1,v2); c = sign(dot(x,n)) * norm(x); a = atan2d(c,dot...

1 month ago | 0

| accepted

Internal variables not calculated
Maybe the behavior you are looking for is nested functions. Instead of a function at the end of a script, you have a function w...

1 month ago | 1

Internal variables not calculated
You didn't declare those variables global in the caller. You only have them global in the function. Add the global statements ...

1 month ago | 1

creating an 8x8 matrix using "diag"
2*eye(8)

1 month ago | 1

| accepted

how can i resolve this equation Runge kutta method
You've got a 2nd order equation, so that means you need a 2-element state vector. The two states will be y and y'. All of your...

1 month ago | 0

Appending to an array/vector
We would need to see your code to give a more specific answer, but the general outline is to index into your result vector. E.g....

1 month ago | 0

what wrong in my code when i use ode 45,and what the error are mean
Try changing this [t,y]=ode45('Mass_On_Stick_012345678',tSpan,y0,opts,Parameter); to this [t,y]=ode45(@(t,y)Mass_On_Stick_012...

1 month ago | 1

| accepted

dgemv produces only zero vectors as results
Two things: 1) All of the integers that you are passing into BLAS/LAPACK functions should be the same. Why are you using ptrdi...

1 month ago | 1

| accepted

Create an .m file
To create an .m file for a function named randint, you can do this at the command line as long as the default directory is your ...

1 month ago | 0