y'-sin(4t)=0 y(0)=-0.25. 1. Use Taylor method to solve up to t4 for 20 steps, h=0.1.

1 件のコメント

James Tursa
James Tursa 2016 年 12 月 2 日
What have you done so far? What specific problems are you having with your code?

サインインしてコメントする。

 採用された回答

James Tursa
James Tursa 2016 年 12 月 2 日

0 投票

MATLAB is a 0-based indexing language. So you can't have y(0) in your code. It will need to start at y(1).
y(1)= -0.25;
Also, you need to index into your t vector as t(i):
Dy(i)=sin(4*t(i));

4 件のコメント

James Tursa
James Tursa 2016 年 12 月 2 日
編集済み: James Tursa 2016 年 12 月 2 日
Yes. Make those two changes and your code should run. You can plot the results with:
plot(t,y)
grid on
title('Euler Solution of y''-sin(4t)=0 with y(0)=-0.25')
xlabel('t')
ylabel('y')
You should see a nice oscillating system.
James Tursa
James Tursa 2016 年 12 月 2 日
編集済み: James Tursa 2016 年 12 月 2 日
Taylor method of what order? E.g., the 1st order Taylor method uses only the 1st derivative and as such is equivalent to the Euler method. For higher order Taylor methods you will need to compute higher order derivatives of y to use. E.g.,
y' = sin(4t)
y'' = 4*cos(4t)
y''' = -16*sin(4t)
etc.
Then you would use those to calculate Dy(i), D2y(i), D3y(i) etc according the the Taylor method. Figuratively,
y(i+1) = y(i) + y'*h + (y''/2!)*h^2 + (y'''/3!)*h^3 + ...
You already have the expression for the first derivative y' in your Euler code (the Dy(i) expression). So you just need to code up the higher order derivatives as shown above, and then combine them as shown in the Taylor method expression. I.e., if you stopped at the first derivative y' term in the above Taylor expression, you would get this:
y(i+1) = y(i) + y'*h
which is just the Euler method you have already coded. You just need to expand this for the higher order terms to create your Taylor code.
Hanaa Yakoub
Hanaa Yakoub 2019 年 12 月 31 日
how do you do it for 20 steps if you are only going up to the fourth derivative?
Nusaybah Ar
Nusaybah Ar 2020 年 1 月 8 日
編集済み: Nusaybah Ar 2020 年 1 月 8 日
I've attempted this question for the taylor method and can't seem to be getting an answer. How do i fix this code? Thanks.
h = 0.1; %Time Step
a = 0; %Starting t
b = 2; %Ending t
n = 20; %Number of Iterations
y(i) = -0.25; %Initial Condition
y1=sin(4*t)
y2=4*cos(4*t)
y3= -16*sin(4*t)
y4=-64cos(4*t)
for i = 0:h:2
y(i+1) = y(i) + y1*h + ((y2/factorial(2))*h.^2) +((y3/factorial(3))*h.^3)+(y4/factorial(4)*h.^4)
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2016 年 12 月 2 日

編集済み:

2020 年 1 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by