Answered
how to write matlab code for physics problem?
You do not explicitly state that acceleration is constant, but I assume that is the case. The equations then are simply vf = v...

5 years ago | 0

Answered
I need help for calculating mortgage for a homework problem
OK, so ask yourself what has to happen every month? You get charged interest and you make a payment, right? And you are told t...

5 years ago | 0

Answered
forward euler for a system of equations
I'm assuming this for j=1:t1:dt was meant to be something like this for j=1:t1/dt

5 years ago | 0

Answered
Splitting a vector into a matrix
result = [x(1:2:end) x(2:2:end)]; or result = reshape(x,2,[]).';

5 years ago | 1

| accepted

Answered
Mex file c. Getting different results from matlab
MATLAB stores matrices in column order. E.g., if A is a 2x3 matrix, and p is a pointer to the data area of A in a mex routine, ...

5 years ago | 0

| accepted

Answered
I don't know how to prove sin^2(x)+cos^2(x)=1
[cos(x),sin(x)] is defined to be a point on the unit circle, so by definition we have sin^2(x) + cos^2(x) = 1 always. This isn'...

5 years ago | 0

Answered
Using loops in matrix
So your latest post is a really good effort! A couple of things you are missing from the instructions: "create a new variable ...

5 years ago | 1

Answered
How do I use function for a function which has a matrix with variable index?
You don't have a branch for the AR>Max case. If you hit that condition, the output variables will not be assigned. Also, ContA...

5 years ago | 0

Answered
I do not know why am I getting imaginary numbers.
Look at the following for the values of i you are using: log(1-i) E.g., >> log(-1) ans = 0.0000 + 3.1416i

5 years ago | 0

| accepted

Answered
multiplying matrix by another matrix element and using it in a command
You can use a loop QT = Q .* reshape(T,1,1,[]); e = zeros(size(QT)); for k=1:size(QT,3) e(:,:,k) = expm(QT(:,:,k)); % fi...

5 years ago | 1

Answered
Sparse matrix memory usage clarification
Sparse matrices can be allocated with more than the minimum memory to hold the non-zero elements and their row indexes (see nzma...

5 years ago | 1

Answered
How to name components of a vector to variables
Don't do that. Your downstream programming will be miserable if you do. See this link for better alternatives (cell arrays, st...

5 years ago | 0

Answered
How to assign values to a matrix from index array?
A(sub2ind(size(A),x,y)) = 1;

5 years ago | 0

| accepted

Answered
Find Sum of array
It may be that you have a local variable called sum that is shadowing the MATLAB sum function. Try clearing it first: clear su...

5 years ago | 1

Answered
Using a function in another function
So, normally one would just have f in your work function. E.g., function work(f,a,b) if sign(f(a))~=sign(f(b)) error('a ...

5 years ago | 0

| accepted

Answered
Replacing Set Number of Random rows with a value
Use randperm( ) to generate the random indexes, and then just use these indexes in an assignment.

5 years ago | 0

Answered
is for loop eating my data :)
You need to store your calculations at each iteration in a vector. E.g., k = 0; for l=200:50:700; k = k + 1; v=(3*10...

5 years ago | 0

Answered
Orbital satellite with Runge Kutta 4th Order Numerical Approximation
This code k4r = f1(t(i)+h, r(i)+k3r*h, rdot(i)+k3rdot*h, theta(i)+k3theta*h, thetad(i)+k3r*h); k4rdot = f2(t(i)+h, r(i...

5 years ago | 0

Answered
adding one row of sequential number to matrix corresponded for each row of the given matrix
result = [(0:size(A,1)-1)' , A];

5 years ago | 1

| accepted

Answered
Decimal matrix to binary matrix correspond to each value of decimal matrix.
Maybe this is what you want: >> A=[9 7 15 ; 4 14 8 ] A = 9 7 15 4 14 8 >> cell2mat(arrayfun(@(x)dec...

5 years ago | 0

Answered
how to make a vector of zeros.
n = number of zeros v = zeros(1,n);

5 years ago | 0

| accepted

Answered
Improper negative number representation
IEEE double precision floating point cannot represent the number -6e-9 exactly. What you are seeing is the decimal representati...

5 years ago | 1

| accepted

Answered
Why this matrix involving simple algebra gives me wrong answer?
This (2400-2.*pi.*r.^2)/3.*pi.*r.^2 is not the same as this (2400-2.*pi.*r.^2)/(3.*pi.*r.^2) which is not the same as this ...

5 years ago | 0

Answered
Accessing elements of built in primes function
p = primes(15); p(1) is the first element p(2) is the second element etc.

5 years ago | 0

Answered
error when trying to calculate a limit with double variable.
limit( ) operates on symbolic expressions. E.g., >> syms n >> limit((1+1/n)^n,inf) ans = exp(1) For the numerical approxim...

5 years ago | 0

| accepted

Answered
How to remove repeat entities in a matlab array
unique(your_variable) or unique(your_variable,'stable')

5 years ago | 0

Answered
Why do I get empty double vector
This is normal floating point arithmetic behavior. None of 0.0025 or 1.15 or 1.12 or 1.16 can be represented in IEEE double pre...

5 years ago | 0

Answered
Connect four diagonal win condition
board((r+fours),(c+fours)) is not the diagonal going from board(r,c) to board(r+3,c+3). It is the 2D sub-matrix containing ever...

5 years ago | 0

Answered
Why did Matlab crash when I run mexw64 file ?
In Fortran, NEVER pass literal integers to the API routines because you cannot guarantee the integers will be the correct size n...

5 years ago | 0

| accepted

Answered
Extracting elements common to rows and columns in a matrix
M = your matrix result = M([3,5],4:5) The [3,5] syntax is simply a vector with the indexes specified in any order. They don't...

5 years ago | 0

| accepted

Load more