matlab - Trying to implement Richardson's Extrapolation - Basic Syntax Assistance -


i far have following

    y = log(x);  % ask user input values h , m  % m denotes number of steps of algorithm.   h       = input('input value h: '); m       = input('input value m: ');  %initialize mxm matrix d = zeros(m);  phi = (1/(2*h)) * (y(x+h) - y(x-h)); print(phi); 

i obtain error

error using symengine (line 58) index exceeds matrix dimensions.

error in sym/subsref (line 696) b = mupadmex('symobj::subsref',a.s,inds{:});

error in re (line 12) phi = (1/(2*h)) * (y(x+h) - y(x-h));

first, believe should getting error message x not being defined. second, have no idea matrix dimension error about. third, , importantly, how can declare function phi becomes wrote?

first, believe should getting error message x not being defined.

i'm guessing x defined, or error upon line defining phi. check whether x defined, type "who" or "whos".

second, have no idea matrix dimension error about.

this because y scalar, x + h equal nonzero integer not 1, , you're trying access y(x + h). own edification try setting y equal scalar (e.g. y = 5;) , seeing errors produced indexing in various legitimate , non-legitimate ways (e.g. y(1), y(0), y(3), y(-1), y(1.5)).

third, , importantly, how can declare function phi becomes wrote?

based on context looks want y defined function of x instead of scalar. in other words:

y = @(x)log(x); phi = (1/(2*h)) * (y(x+h) - y(x-h)); 

the code runs without error when change definitions above.

one other error run into: print command not you're looking - prints figure file. you're looking for:

disp(phi); 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -