MATLAB Answers

0

why doesnt matlab calculate this divisions

Asked by emre can gunes on 28 Apr 2019
Latest activity Answered by Stephan
on 28 Apr 2019
function deneme()
syms x y
f = @(x,y) (((1/5) * (exp(-2 * x) - 6 * sin(x * y))) - 0.4325 )
g = @(x,y) (((1/5) * (x^2 * y + 6 * cos(x))) - 0.0643 )
J = jacobian([((1/5) * (exp(-2 * x) - 6 * sin(x * y))) - 0.4325 , ((1/5) * (x^2 * y + 6 * cos(x))) - 0.0643],[x , y])
A = inv(J)
H(x,y) = det(J)
C(x,y) = A(1,1)
D(x,y) = A(1,2)
E(x,y) = A(2,1)
F(x,y) = A(2,2)
error = 100;
tc = 10^(-20);
i = 0;
x0 = 1;
y0 = 1;
x(1) = x0
y(1) = y0
while (error > tc)
if H(x(i+1),y(i+1)) == 0
fprintf('System cannot be solved')
end
x(i+2) = eval(x(i+1) - C(x(i+1),y(i+1)) * feval(f,x(i+1),y(i+1)) + D(x(i+1),y(i+1)) * feval(g,x(i+1),y(i+1)));
y(i+2) = eval(y(i+1) - E(x(i+1),y(i+1)) * feval(f,x(i+1),y(i+1)) + F(x(i+1),y(i+1)) * feval(g,x(i+1),y(i+1)));
e1 = abs((x(i+2)-x(i+1))/x(i+2)) * 100;
e2 = abs((y(i+2)-y(i+1))/y(i+2)) * 100;
error = eval(max(e1,e2))
i = i+1;
end
disp(error)
fprintf('After %d iterations the approx root is %f %f',i,x(i+1),y(i+1))
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephan
on 28 Apr 2019

Hi,
x,y are symbolic variables. Matlab shows them this way, due to accurracy. Insert a type cast to make them numbers:
x = double(x);
y = double(y);
Best regards
Stephan

  0 Comments

Sign in to comment.