# Euler's Method

์กฐํ ์: 26 (์ต๊ทผ 30์ผ)
Matthew Russell 2019๋ 6์ 10์ผ
๋ต๋ณ: Shagufta Perveen 2021๋ 5์ 24์ผ
Hello,
New Matlab user here and I am stuck trying to figure out how to set up Euler's Method for the following problem:
?โฒ =sin(?)โ(1โ?) with ?(0)=?0 and ?โฅ0
The teacher for the class I am taking provided us with the following code to use for Euler's Method. The code has been modified with my most recent attempt to solve the problem above. His template worked fine for the problem listed at the top and several others, but when I changed out the variables for the problem above and I get the error message listed at the bottom. I have tried various ways of inputing the code that I found on YouTube or Google searches and none have been able to help. What am I doing wrong?
%This code solves the differential equation y' = 2x - 3y + 1 with an
%initial condition y(1) = 5. The code uses
%the Euler method, the Improved Euler method, and the Runge-Kutta method.
%The function f(x,y) = 2x - 3y + 1 is evaluated at different points in each
%method.
h = 1/16; %Time Step
a = 0; %Starting x
b = 20; %Ending x
n = 321; %Number of Iterations
x = zeros(n,1);
y = zeros(n,1);
x = linspace(a,b,n)'; %Array of x values where evaluate the function
y(1) = 6; %Initial Condition
for i = 1:n-1
y(i+1) = y(i) + h *((sin(x) * ( 1 - y(i)) ; %Euler's Method
end
[x y] %Table showing x and y values
Error: File: Euler_Method.m Line: 21 Column:
47
Invalid expression. When calling a function
or indexing a variable, use parentheses.
Otherwise, check for mismatched delimiters.
##### ๋๊ธ ์: 0์ด์  ๋๊ธ -2๊ฐ ํ์์ด์  ๋๊ธ -2๊ฐ ์จ๊ธฐ๊ธฐ

๋๊ธ์ ๋ฌ๋ ค๋ฉด ๋ก๊ทธ์ธํ์ญ์์ค.

### ์ฑํ๋ ๋ต๋ณ

Debasish Samal 2019๋ 6์ 10์ผ
There is a parentheses mismatch in your code for the euler's method.
Replace that line with:
y(i+1) = y(i) + h *(sin(x) * ( 1 - y(i))) ; %Euler's Method
##### ๋๊ธ ์: 1์ด์  ๋๊ธ -1๊ฐ ํ์์ด์  ๋๊ธ -1๊ฐ ์จ๊ธฐ๊ธฐ
Matthew Russell 2019๋ 6์ 11์ผ
Thank you so much. I had to change sin(x) to sin(x(i)) for it to work, but it worked perfect after that.

๋๊ธ์ ๋ฌ๋ ค๋ฉด ๋ก๊ทธ์ธํ์ญ์์ค.

### ์ถ๊ฐ ๋ต๋ณ (2๊ฐ)

Raghunandan V 2019๋ 6์ 10์ผ
Hi,
Simple code error. Check this line
y(i+1) = y(i) + h *((sin(x(i)) * ( 1 - y(i)))) ; %Euler's Method
##### ๋๊ธ ์: 1์ด์  ๋๊ธ -1๊ฐ ํ์์ด์  ๋๊ธ -1๊ฐ ์จ๊ธฐ๊ธฐ
Matthew Russell 2019๋ 6์ 11์ผ
Thank you!

๋๊ธ์ ๋ฌ๋ ค๋ฉด ๋ก๊ทธ์ธํ์ญ์์ค.

Shagufta Perveen 2021๋ 5์ 24์ผ
y = te3t โ 2y, 0 โค t โค 1, y(0) = 0, with h = 0.5
if true
% code
end
##### ๋๊ธ ์: 0์ด์  ๋๊ธ -2๊ฐ ํ์์ด์  ๋๊ธ -2๊ฐ ์จ๊ธฐ๊ธฐ

๋๊ธ์ ๋ฌ๋ ค๋ฉด ๋ก๊ทธ์ธํ์ญ์์ค.

### ์นดํ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์์ Mathematics์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ

R2019a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by