why doesnt matlab calculate this divisions

7 visualizaciones (últimos 30 días)
emre can gunes
emre can gunes el 28 de Abr. de 2019
Comentada: hadoune oussama el 30 de Sept. de 2021
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

Respuestas (2)

Stephan
Stephan el 28 de Abr. de 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 comentarios
hadoune oussama
hadoune oussama el 30 de Sept. de 2021
it doesn't work!
hadoune oussama
hadoune oussama el 30 de Sept. de 2021
here is a pic of the results!

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 30 de Sept. de 2021

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by