Determine the roots of the simultaneous nonlinear equation by fixed point iterations

조회 수: 14 (최근 30일)
(x-4)^2 + (y-4)^2 = 5
x^2 + y^2 = 16
here's my code
f = @(x) (5 - (y-4).^2)^(1/2) + 4;
g = @(y) (16 - x.^2)^(1/2);
x0 = 1.5;
y0 = 2.5;
rt = fixed(f,g,1.5,2.5);
__________________
function (x,y) = fixed(f,x,x0,y0)
x0 = 1.5;
y0 = 2.5;
i = 1;
x(1) = x0;
x(2) = g(x0);
y(1) = y0;
y(2) = f(y1);
for i = 0
i = i+1;
x(i) = f(x(i-1));
y(i) = g(x(i-1));
end
x = x(end);
y = y(end);
  댓글 수: 1
Quinten
Quinten 2016년 10월 24일
I get an error saying "Error: File: fixed.m Line: 1 Column: 10 Unbalanced or unexpected parenthesis or bracket.
Error in fixed_iter (line 10) rt = fixed(f,g,1.5,2.5);"

댓글을 달려면 로그인하십시오.

답변 (2개)

Roger Stafford
Roger Stafford 2016년 10월 25일
편집: Walter Roberson 2016년 10월 25일
Using your “fixed point” iteration method to solve those two equations is a bad idea. There are much simpler ways of solving such equations. The problem is equivalent to finding the two intersections of two circles. In case it is of interest I give a method of doing this at the Answers site:

Walter Roberson
Walter Roberson 2016년 10월 25일
function [x,y] = fixed(f,x,x0,y0)
Note: your file appears to be named fixed.m and you appear to be trying to mix functions with script. Before R2016b it was not permitted to define a function in a script file. As of R2016b it is permitted, but the functions you define must not have the same name as the script file. If you wish to have function fixed in your script file then you will need to have the file named something else like testfixed.m

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by