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

5 ビュー (過去 30 日間)
Quinten
Quinten 2016 年 10 月 24 日
編集済み: Walter Roberson 2016 年 10 月 25 日
(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 Center および File ExchangeNewton-Raphson Method についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by