Answered
How to use optimizer with ode45?
You would start by writing code to numerically integrate your DE using ode45. You have a simple 1st order ODE. There is an examp...

8 years ago | 0

Answered
How to find the descending index in each row of a matrix?
E.g., assuming there is always a decrease: [~,x] = max(diff(A,1,2)<0,[],2); result = x + 1; If there is not a decreas...

8 years ago | 0

| accepted

Answered
Limiting Precision on MATLAB
With floating point calculations you often need to use tolerances, so this if( forceSum < 0 ) would be coded something l...

8 years ago | 1

Answered
How can I make a quadratic approximation given two points and incidence angle at the second point?
Maybe something like this is what you need? (assuming by "incidence angle" you mean slope) % Construct some sample data for...

8 years ago | 0

Answered
Editing elements of vector inside mex function slow
I can think of no reason why writing to memory from a mxArray (off of the heap) should take a significantly different amount of ...

8 years ago | 1

| accepted

Answered
cross product of two points
You probably have inadvertently created a variable named "cross". Delete this variable that is shadowing the MATLAB function "cr...

8 years ago | 0

Answered
ode45 error "Undefined function or variable"
Here is your derivative function signature: function drdt = boost(m0,Cd,G,Me,Re,Area,tspan,Thrust) As you can see, there...

8 years ago | 0

Answered
Error in outputting a variable from function
Change your switch-case logic to if-then-else logic. E.g., switch h >= 0 && h <= 105 case h >= 0 && h < 11 ...

8 years ago | 0

Answered
How to fix this error
You need to save the output of fun into specific elements of T, P, and D. E.g., h=0:1:105; for k=1:numel(h) [T(k)...

8 years ago | 0

| accepted

Answered
What is wrong with my bisection method code?
You don't show us how you are calling this function, so it is hard to advise you what to correct for that. For the code itsel...

8 years ago | 3

| accepted

Answered
All possible combinations of 0's and 1's
One way: s = 2^sum(a); result = repmat(a,s,1); % or result = zeros(s,size(a,2)); result(:,logical(a)) = dec2bin(0:s-1...

8 years ago | 2

Answered
Why position does not have to be limited between +pi/2 and -pi/2
Can you use atan2 instead of atan?

8 years ago | 0

Answered
index exceeds matrix dimensions
Type the following at the command line: dbstop if error Then run your code. When the error occurs, the debugger will pau...

8 years ago | 0

| accepted

Answered
How to perform vector Matrix Multiplication
First I would suggest you reorder your dimensions to put the 4x4 matrices first, so that P is 4x4xn and T is 4x4xn. That way al...

8 years ago | 1

Answered
x = j:i:k creates a regularly-spaced vector x using i as the increment between elements. What about x = j:i:k:m? or j:i:k:m:n?
This is simply left-to-right operator evaluation. j:i:k:m:n evaluates as (j:i:k):m:n And, as stated in the doc: ...

8 years ago | 0

| accepted

Answered
Error: Conversion to double from function_handle is not possible. Error in homework4 (line 18) deltaf(k) = function_fd(f,2,h(k));
deltaf is a double vector, but function_fd returns a function handle. You can't convert a function handle to a double, hence the...

8 years ago | 1

Answered
I can't call this function from the command window. The function is meant to output values and plot graphs from a data file.
Don't put literal values in the output of a function definition line. Use a variable instead. E.g., function [C Gouws,19114...

8 years ago | 0

Answered
Double for loop in a random walk. How do I loop over all particles simultaneously instead of looping the amount of steps for each separate particle one at a time?
If you want to walk all of the particles simultaneously, then simply reverse the order of your for-loops: for n = 1:N % Loop...

8 years ago | 0

Answered
How to make a for loop that sums all the odd values in the array?
Initialize your summing variable prior to the loop: summedValue = 0; Then inside the loop, add to it: for i = 1:...

8 years ago | 1

Answered
Can anyone help me solve this Matlab (while loop) series summation problem?
To make things easier on yourself, why not use the exact same variable names as the question? E.g., use k as the indexing variab...

8 years ago | 2

Answered
Binary to floating point representation using IEEE-754
Any method you choose is going to have to make assumptions about bit/byte ordering and the handling of the special inf, nan, and...

8 years ago | 4

Answered
Averaging rows with rows previous
Assuming the average includes the row in question: x = your matrix result = cumsum(x)./(1:size(x,1))'; Or for earlier...

8 years ago | 0

| accepted

Answered
Replace zeros with text
_"... I'm trying to make a column n rows long that says the word 'hello' ..."_ a = ('hello')'; The above results in a c...

8 years ago | 0

Answered
Would you redefine the value of your loop index variable within the for loop?
Only if you want obfuscated code that is hard to understand and debug. In other words, no. Don't do this. If you need to redefin...

8 years ago | 0

Answered
Conditional entry-wise matrix operation
Hints: What does the expression -abs(X) do in relation to your condition of X_ij > 0? Could you use this in your formula fo...

8 years ago | 0

| accepted

Answered
what is the difference between = and ==?
= is used for an assignment == is the element-wise equality comparison operator <https://www.mathworks.com/help/matlab/mat...

8 years ago | 5

Answered
How to iteratively split a matrix into multiple matrices according to a condition?
Assuming values in 1st column are non-negative, you could put the results into a cell array: M = your matrix M1 = M(:,1)...

8 years ago | 1

| accepted

Answered
How to combine 4 Matrices into one matrix
E.g., result = zeros(m,p,n); % assuming your matrices are m x p sized for k=1:n result(:,:,k) = the matrix calcul...

8 years ago | 0

Answered
Incorrect results using Runge Kutta 5th order method
I have already answered this on your other thread, but will re-post here. The 'h' variable in your t and z updates is supposed t...

8 years ago | 0

| accepted

Answered
Runge Kutta 5th order help, error message "Index exceeds matrix dimensions."
You don't have any x(i+1)=etc line. Since you don't set the next value of x, when you get to the second loop iteration the x(2) ...

8 years ago | 0

| accepted

Load more