why doesnt matlab calculate this divisions

7 ビュー (過去 30 日間)
emre can gunes
emre can gunes 2019 年 4 月 28 日
コメント済み: hadoune oussama 2021 年 9 月 30 日
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

回答 (2 件)

Stephan
Stephan 2019 年 4 月 28 日
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 件のコメント
hadoune oussama
hadoune oussama 2021 年 9 月 30 日
it doesn't work!
hadoune oussama
hadoune oussama 2021 年 9 月 30 日
here is a pic of the results!

サインインしてコメントする。


Walter Roberson
Walter Roberson 2021 年 9 月 30 日
  1 件のコメント
hadoune oussama
hadoune oussama 2021 年 9 月 30 日
it does really work!! thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by