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

5 visualizaciones (últimos 30 días)
(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 comentario
Quinten
Quinten el 24 de Oct. de 2016
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);"

Iniciar sesión para comentar.

Respuestas (2)

Roger Stafford
Roger Stafford el 25 de Oct. de 2016
Editada: Walter Roberson el 25 de Oct. de 2016
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 el 25 de Oct. de 2016
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

Community Treasure Hunt

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

Start Hunting!

Translated by