Need help calculating a system of ODE's using the forward Euler method!
Show older comments
Help!
Have been given an assingment and am stuck on the start of the question, and have no previous examples to help me with. The following is the basis for my question which im stuck on. Any help would be greatly appreciated.

3 Comments
Shaun Devonshire
on 23 Mar 2020
John D'Errico
on 23 Mar 2020
There are several errors that new users make. But it is difficult to know which, as the code you show generally looks reasonable. The most obvious problem seems to be in the use of the beta function, which suggests to me that you have a problem there, as most likely, you may not even know you were trying to use the beta function since it was called incorrectly.
When you get an error, show the ENTIRE text of the errror message in red. That typically allows people to know what you are doing wrong.
Shaun Devonshire
on 23 Mar 2020
Answers (1)
darova
on 23 Mar 2020
I have some tips:
These a constants, not functions. YOu should declare them
betax = 1;
betay = 1;
maxx = 1000;
maxy = 1000;

You are using x and y in a wrong way. Look

1 Comment
John D'Errico
on 23 Mar 2020
To add a few points:
Your immediate problem is in not using the correct operator. y is a vector, of length 2. You wrote this:
f1_dot = y*beta(y)*(1-(y/max(y))-(x/max(x)));
Or, now this:
f1_dot = y*(1-(y/1000)-(x/1000));
In either case, on the face of things, seems vaguely logical. In fact though, you have a problem.
y is avector. When you want to erform a multiplication where you want to multiply every element of two vectors, you need to use .* not * as an operator.
For example:
X = 1:3
X =
1 2 3
>> X*X
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows
in the second matrix. To perform elementwise multiplication, use '.*'.
>> X.*X
ans =
1 4 9
The same rule applies to powers of vector elements, and when you divide one vector by another. Additions and subtractions are not a problem. And you can multiply a vector by an scalar using the * operator. But otherwise, get used to using .* where that is appropriate.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!