MATLAB Answers

Euler method error in code Index exceeds the number of array elements (1). in my my code

조회 수: 1(최근 30일)
my code
b=input('enter the starting value of b here ')
a=input('enter the starting value of a here ')
h= 15
x(1)= 0
y(1)= 0
for n=1:h:i
if x <= 400

  댓글 수: 2

Anas Lunat
Anas Lunat 17 Nov 2019
question asked this
boatman is charged with operating a ferry across the river Nile in a place where the river is 400 m wide. The boat is navigated from starting point (A) such that it is always pointing at the destination of end point (B) at a speed of a m2 There is a current running in the river of b ms-1 that carriesthe vessel downstream. Using an X, Y coordinate system as shown in Figure 1, write a MATLAB script that adopts Euler’s method to find locations of the vessel as it crosses the river and plots the path of the ferry. Test the script using different speeds for the vessel and current, in each case finding how long it takes to cross the river.
the graph starting point for x and y would b '0' using euler new values would be generated for x and y

로그인 to comment.

채택된 답변

Fabio Freschi
Fabio Freschi 17 Nov 2019
Checking the sintax of the code only I see 3 issues
1) In the for loop you wrote a(400-x(n)), that is you are addressing the position 400-x(n) = 400 when n = 1 of the variable a. but a is a scalar. so I guess you forgot an operator like, for example a*(400-x(n)) or a+(400-x(n))...
2) you are using sqr instead of sqrt to extract the square root
3) you should preallocate your vectors x and y as x = zeros(i,1); y = zeros(i,1);
Note also that using i as variable can be misleading because it is often used as index

  댓글 수: 0

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by