Help me, engineers! Using MATLAB

QueHuong

Platinum Member
Nov 21, 2001
2,098
0
0
I have this homework problem for solving 6 non-linear equations for 6 variables using Newton's Method.

I'm trying to do this example problem in the book to help me get started, but I'm stuck on the easy part because I don't know MATLAB's syntax well enough.

The program and sample problem
Sample problem continued

You don't really have to know Newton's Method to help, just need to know how to use MATLAB a little bit. So I typed the given program in the blue box in an M-file. The part I'm confused about is calling the function

Newton_sys(F, JF, x0, tol, max_it)

I don't know how to define F and JF to be able to call the function. If you look at the two scanned pages, you'll see the system of 3 equations, and those are what I'm supposed to define for F and JF, but I don't know how.

Here's what I have:

In the file func.m:

function F = func(x1, x2, x3)
F = [ (x1^2 + x2^2 + x3^2 -1)
(x1^2 + 0 + x3^2 - .25)
(x1^2 + x2^2 -4*x3 + 0) ];

In the file myfunc.m:

function B = myfunc(x1, x2, x3)
B = [2*x1 2*x2 2*x3
2*x1 0 2*x3
2*x1 2*x2 -4];

I defined guess as [1 1 1]


And in MATLAB"s command window, I tried calling Newton_sys with:

C = Newton_sys('func', 'myfunc', guess, .00001, 200)



And it doesn't work. All I really need (ASAP please!) is how do I get the system of 3 equations and its Jacobian (see scanned pages) into the vectors 'F' and' JF' so it can be used to solve with the function Newton_sys. Thanks.
 

Atomicus

Banned
May 20, 2004
5,192
0
0
I took Matlab programming a year ago, but I forgot all but the simple commands. Show me the entire code once you're done and the error message that comes up when you run.
 

QueHuong

Platinum Member
Nov 21, 2001
2,098
0
0
That was basically the whole code. The error was "x2 is not defined" but ignore that since I dont think the error really has anything to do with it since I just tried to type anything down to see if it works.

Overall, my question is, given the system of equation f1, f2, f3, and its Jacobian (its Jacobian is already solved for, see pictures), how do I put the system of equation into the vector 'F' and the Jacobian in "JF"? Basically, if you were trying to do the example question yourself, how would you do it?
 

QueHuong

Platinum Member
Nov 21, 2001
2,098
0
0
That isn't the problem; I was wondering whether or not I should have posted what I had so far, because I know what I had so far was totally wrong and that might throw people off. So just ignore what I had in func.m and myfunc.m.

Think of it as being just given the code in the picture and the equations in Example 5.2, what would you do run the example problem, totally ignoring what I had and starting from scratch?
 

BullsOnParade

Golden Member
Apr 7, 2003
1,259
0
0
pass the function Newton_sys the functions F and JF along with their arguments:

Newton_sys(F(x1, x2, x3),B(x1, x2, x3), x0, tol, max_)

lemme know if that works
 

QueHuong

Platinum Member
Nov 21, 2001
2,098
0
0
That's the problem...I don't know how to define F and B in their respective M-files.
 

RichieZ

Diamond Member
Jun 1, 2000
6,551
40
91
haha i used to know how to do all that, but its been like a yr or so. i dislike matlab with a passion