PDA

View Full Version : สอบถามเกี่ยวกับ numerical ใน maple 15


bungkee
25 มิถุนายน 2012, 01:15
จงหาคำตอบของ x log x = 4.772393 โดยวิธีนิวตัน-ราฟสัน

สามารถเขียน CODE MATLAB ได้ยังไงหรอคะ ?

พอเขียนแบบข้างล่าง ซึ่งดูตัวอย่างจากหนังสือมา มันฟ้อง error อะ

function [xt,yt] = NewtonEx(fun,x1,tol,max)
syms x;
f = fun; % ERROR Not enough input arguments.
df = diff(f,x);
xt(1) = x1;
yt(1) = subs(f,x,xt(1));
y_pr(1) = subs (df,x,xt(1));
for i = 2 : max
xt(1) = xt(i-1)-yt(i-1)/y_pr(i-1);
yt(1) = subs(fun,x,xt(i));
if abs(xt(i)-xt(i-1))< tol
disp('Newton method has converged'); break;
end
y_pr(i) = subs(df,x,xt(i));
iter = i;
end
if iter >= max
disp('zero not found to desire tolerance');
end
n = length(xt);
k = 1:n;
out = [k' xt' yt'];
disp(' step x y');
fprintf(1,'%10d %12.7f %12.7f\n',out');
end

มันเออเร่อตรงที่บอกอะค่ะ หมายความว่าอย่างไรหรอ ?