why doesnt matlab calculate this divisions

16 Ansichten (letzte 30 Tage)
emre can gunes
emre can gunes am 28 Apr. 2019
Kommentiert: hadoune oussama am 30 Sep. 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

Antworten (2)

Stephan
Stephan am 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

Walter Roberson
Walter Roberson am 30 Sep. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by