0

So, these problem appears when I try to run my code in Octave:

*

T(1.2): subscripts must be either integers 1 to (2^63)-1 or logic

I try an euler method to study and here's my code

function fxy = fa(x,y)

% fa merupakan fungsi persamaan diferensial

fxy = x^2 - 4*y;

end

function [T, Y] = euler(f, a, b, y0, n)

% fungsi EULER penyelesaian numerik persamaan diferensial dengan metode
% Euler explisit

h = (b-a)/n;
Y = zeros(n+1,1);
T = zeros(n+1,1);

%syarat awal
T(1) = a;
Y(1) = y0;

% jalankan sebanyak n langkah
for i = 1:n
    fi = f(T(i), Y(i));
    Y(i+1) = Y(i) +  h*fi;
    T(i+h) = T(i) + h;
end

    x0 = 0;   % batas bawah/ bayas awal
    xm = 1;   % batas atas / batas akhir
    y0 = 1;   %syarat batas awal
    n = 5;  % banyaknya segmen / langkah


    [x,y] = euler(@fa, x0, xm, y0, n);

Can someone help to fix my problem?

  • please use English in comments, https://stackoverflow.com/help/how-to-ask – alex3465 Aug 31 '21 at 09:23
  • What input do you use? What is the value of `h` when your code fails? It would be better to post the entire error message. – beaker Aug 31 '21 at 14:49
  • See `T(i+h) = T(i) + h;`, I'll vote for closing due to typo. – Lutz Lehmann Aug 31 '21 at 19:06
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 03 '21 at 20:34
  • Further to Lutz's comment above, changing that line to`T(i+1) = T(i) + h;` will get rid of the error. Whether it then gives the right answer is a different question, though I think it will. – Howard Rudd Sep 04 '21 at 19:56

0 Answers0