Answered
Hi, I'm writing a Runge Kutta function to solve a higher order differential equation and I need to get the error to around 10^-11.
You need to rewrite your derivative function as a vector function to account for the higher order derivatives. You've got a 4x1...

9 years ago | 1

| accepted

Answered
Multiply Each Matrix in Cell Array by a Different Value
result = cellfun(@times,A,num2cell(b),'uni',false); But this just moves the loops (which are part of cellfun) into the back...

9 years ago | 1

| accepted

Answered
create binary 0 and 1
subA = A(sum(A,2)==3,:); For subB it is not entirely clear to me what you want. Do you want the rows of A arranged so that...

9 years ago | 0

| accepted

Answered
sort from largest to smallest
sort(A(:,1),'descend') If you want to sort the matrix A by rows based on the first column, then e.g. flipud(sortrows(A...

9 years ago | 2

| accepted

Answered
increasing spdiags matrix at each iteration
A2 = repmat(A2,1,i); But it seems to me that you may be running into memory problems with this, since A2 is recursively usi...

9 years ago | 0

Answered
how do i select a number from a set randomly
If you are just interested in the values -1 and 1, you could do something like this: Asimulac = round(rand(101,5))*2-1; ...

9 years ago | 0

Answered
Problems with simulation of Earth-Moon trajectories around the Sun
I haven't looked at your derivative equations yet, but the order is definitely wrong. E.g., take the first two elements: i...

9 years ago | 0

| accepted

Answered
Reverse the value in multiple columns
x = your matrix c = a vector with column numbers to reverse x(:,c) = 6 - x(:,c); e.g., >> x = randi(5,6,6) % <-...

9 years ago | 0

Answered
How to plus two nan matrix
c = a + b; c(isnan(c)) = a(isnan(c)); c(isnan(c)) = b(isnan(c));

9 years ago | 1

| accepted

Answered
How do I make a function file that can calculate the modified eulers method?
For Modified Euler's Method, you simply average the derivative at your initial point and next point, and then use that to take a...

9 years ago | 0

Answered
how to cut the matrix
x = [1 0.1 2 0.2 3 0.3 4 0.5 5 0.6 6 1.2 7 1.2 8 1.3]; >> y = x(x(:,2)<1.2,:) y = 1.0000 ...

9 years ago | 0

| accepted

Answered
Help with creating a modified Euler method for a bungee jumping question
For Modified Euler's Method, e.g. this link: https://mat.iitm.ac.in/home/sryedida/public_html/caimna/ode/euler/ie.html Bas...

9 years ago | 0

Answered
Which standard MATLAB functions do you shadow with your own version, and why?
I have intentionally shadowed fopen, fread, fwrite, fclose before. Options that would read/write VAX binary format numbers were...

9 years ago | 3

Answered
I have 100 2D matrix .. After each matrix, I calculate the sum of elements inside it .. I want to see only the matrices with summation result under certain value (such as: 23). How can I do this?
E.g., if they were stored in a 3D array: >> m = randi(10,3,3,5) % some random data m(:,:,1) = 5 8 7 ...

9 years ago | 0

Answered
Anyone know what I am getting this error?
Use the debugger. First, type the following: dbstop if error Then run your code. When the error occurs, the program wi...

9 years ago | 1

Answered
Incorrect number of arguments into mex file
Particularly for Fortran, you should always use the exact signature that is in the doc. Sometimes that signature changes from r...

9 years ago | 1

| accepted

Answered
What if I find an error in the documentation
Go to this link: https://www.mathworks.com/support/bugreports/ Click on the green "Report a Bug" near the top right, and g...

9 years ago | 0

| accepted

Answered
Accessing an array that is singles which is part of a structure is really slow
Timings like this are inherently unreliable. The actual operations involved are extremely simple, so the runtimes can easily be...

9 years ago | 0

Answered
I am trying to plot within a for loop, but it is only plotting the last set of data. How would I get all three sets of data in the same graph. The code is included
Change hold off to hold on Also, I assume those labels and title were meant to be on the plot, not set as actua...

9 years ago | 0

Answered
Random path coordinates in 2D within a unit square
Any restrictions on the path? E.g., would 1000 random points suffice: mypath = rand(1000,2); % <-- each row is an (x,y) p...

9 years ago | 0

Answered
How to quary (building a new matrix based on some information)
C = B(ismember(B(:,1),A(:,1)),:); D = C(C(:,2)==1,:);

9 years ago | 0

Answered
how to assign different value for each input
Not quite sure what you really want, but here is a start: ci = [0.9 0.95 0.99 0.999]; c = [1.645 1.960 2.576 3.291]; ...

9 years ago | 0

Answered
How do I combine matrices of different dimensions which are obtained in a for loop?
Do you mean something like this? result = zeros(10,11); for k=1:10 result(k,1:k+1) = 1:k+1; % or whatever the co...

9 years ago | 0

Answered
Error is compiling mex file in MATLAB with intel compiler "Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2010"
For a fixed format source file, the continuation line must have the continuation character in column 6. You have several lines ...

9 years ago | 0

Answered
Further improvement of matrix inversion
_How can we further speed up this inversion if we know from the beginning that Cholesky decomposition can apply in our matrix?...

9 years ago | 1

| accepted

Answered
Why can't Mex C/C++ Code With Xcode on Mac (MatlabR2015a)?
There are no spaces between the directive and the token. So change these lines #ifndef_DOUBLEIT_H_ #define_DOUBLEIT_H_ ...

9 years ago | 0

| accepted

Answered
How to merge matrices generated from a for loop into one matrix.
E.g., as a matrix of columns: solutionV = zeros(___,numel(k)); % <-- fill this in to pre-allocate : solutionV(...

9 years ago | 0

Answered
What is wrong with my code? Cycle while help
You need to break out of the loop when you hit the bottom corner. Also, you need to add in code that updates m and/or n as you ...

9 years ago | 1

| accepted

Load more