NewtonRaphson Approx help

MATLAB-specific help discussions.

NewtonRaphson Approx help

Postby tashalla » Thu Sep 27, 2012 9:30 am

This is my first time trying to code in Matlab and I can't get my code to work. Please help me. The code is meant to do a newton raphson approximation to find the root of two equations u and v. The two functions funcs and twoEqNewtonRaphson are in separate .m files. When I try to run the main code nothing happens. There is no error message, the Matlab program just freezes and says busy. I think the while loop is to blame but I can't see anything wrong. I would greatly appreciate any help

Main code:

[xr, yr, xe, ye] = twoEqNewtonRaphson(1.2, 1.2, 0.0001);
rootStmt = sprintf('The approxiamate root of the system is at the coordinate point (%0.5f, %0.5f).', xr, yr);
errorStmt = sprintf('The error associated with the x-coordinate is %0.5f and the error associated with the y-coordinate is %0.5f.', xe, ye);

function[xroot, yroot, xerror, yerror] = twoEqNewtonRaphson(x_o, y_o, e_s)
xerror = 1;
yerror = 1;
xroot = x_o;
yroot = y_o;
[u, v, ux, uy, vx, vy, D] = funcs(xroot, yroot);
while(abs(xerror) > e_s && abs(yerror) > e_s)
prevx = xroot;
prevy = yroot;
xroot = xroot - (u*vy-v*uy)/D;
yroot = yroot - (v*ux-v*vx)/D;
xerror = xroot-prevx/xroot;
yerror = yroot-prevy/yroot;
[u, v, ux, uy, vx, vy, D] = funcs(xroot, yroot);

function [u, v, du_x, du_y, dv_x, dv_y, D] = funcs(x, y)
u = (x*x)-(5.*x*y)-y;
v = y+(x*x)-x-0.75;
du_x = (2.*x)-(5.*y);
du_y = (-5.*x)-1;
dv_x = 2.*x-1;
dv_y = 1;
D = (du_x)*(dv_y)-(du_y)*(dv_x);
Posts: 1
Joined: Thu Sep 27, 2012 9:26 am

Return to MATLAB Help

Who is online

Users browsing this forum: No registered users and 2 guests