why doesnt matlab calculate this divisions
Show older comments
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

Answers (2)
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
2 Comments
hadoune oussama
on 30 Sep 2021
it doesn't work!
hadoune oussama
on 30 Sep 2021
here is a pic of the results!
Walter Roberson
on 30 Sep 2021
0 votes
In new enough versions you can control this with sympref
1 Comment
hadoune oussama
on 30 Sep 2021
it does really work!! thank you
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!