473,795 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newton Raphson not working

15 New Member
Hi guys I allready oppened another thread to know if someone can help me to solve a 3 non linear equation system. I tryed this code to make the newton raphson method to work, but insted of converging it is diverging. Can someone please help me? Thank's!

Expand|Select|Wrap|Line Numbers
  1. 'Cálculo do Sistema para obter os cossenos directores através do método Newton-Raphson
  2.  
  3.         Dim nr, aux1, aux2, aux3, lll, mmm, nnn, ff, gg, hh, ite As Double
  4.  
  5.         'Condiçăo inicial l=m=n=1
  6.         lll = 0.5
  7.         mmm = 0.5
  8.         nnn = 0.5
  9.  
  10.         'For nr = 0 To 2
  11.         For ite = 0 To 20
  12.  
  13.             Dim Gauss As New GaussJ
  14.             Gauss.InpNumEq = 3
  15.  
  16.             Gauss.ManagMat(0, 0) = y(0, 0) - aux(2)
  17.             Gauss.ManagMat(0, 1) = y(0, 1)
  18.             Gauss.ManagMat(0, 2) = y(0, 2)
  19.             Gauss.ManagMat(1, 0) = y(1, 0)
  20.             Gauss.ManagMat(1, 1) = y(1, 1) - aux(2)
  21.             Gauss.ManagMat(1, 2) = y(1, 2)
  22.             Gauss.ManagMat(2, 0) = 2 * lll
  23.             Gauss.ManagMat(2, 1) = 2 * mmm
  24.             Gauss.ManagMat(2, 2) = 2 * nnn
  25.  
  26.             'f(l,m,n)
  27.  
  28.             ff = (y(0, 0) - aux(2)) * lll + y(0, 1) * mmm + y(0, 2) * nnn
  29.             gg = y(1, 0) + (y(1, 1) - aux(2)) + y(1, 2)
  30.             hh = lll ^ 2 + mmm ^ 2 + nnn ^ 2 - 1
  31.  
  32.             Gauss.ManagCons(0) = -ff
  33.             Gauss.ManagCons(1) = -gg
  34.             Gauss.ManagCons(2) = -hh
  35.  
  36.             Gauss.gaussj()
  37.             TextBox14.Text += Environment.NewLine
  38.             TextBox14.Text += "******x1= " & Format(Gauss.ManagCons(0), "0.0000")
  39.             TextBox14.Text += Environment.NewLine
  40.             TextBox14.Text += "******x2= " & Format(Gauss.ManagCons(1), "0.0000")
  41.             TextBox14.Text += Environment.NewLine
  42.             TextBox14.Text += "******x3= " & Format(Gauss.ManagCons(2), "0.0000")
  43.  
  44.             lll = Gauss.ManagCons(0) + lll
  45.             mmm = Gauss.ManagCons(1) + mmm
  46.             nnn = Gauss.ManagCons(2) + nnn
  47.  
  48.  
  49.             TextBox14.Text += Environment.NewLine
  50.             TextBox14.Text += Environment.NewLine
  51.             TextBox14.Text += "l=" & lll
  52.             TextBox14.Text += Environment.NewLine
  53.             TextBox14.Text += "m=" & mmm
  54.             TextBox14.Text += Environment.NewLine
  55.             TextBox14.Text += "n=" & nnn
  56.         Next ite
  57.         ' Next nr
  58.  
May 16 '07 #1
3 3449
Dököll
2,364 Recognized Expert Top Contributor
Hi guys I allready oppened another thread to know if someone can help me to solve a 3 non linear equation system. I tryed this code to make the newton raphson method to work, but insted of converging it is diverging. Can someone please help me? Thank's!

Expand|Select|Wrap|Line Numbers
  1. 'Cálculo do Sistema para obter os cossenos directores através do método Newton-Raphson
  2.  
  3.         Dim nr, aux1, aux2, aux3, lll, mmm, nnn, ff, gg, hh, ite As Double
  4.  
  5.         'Condiçăo inicial l=m=n=1
  6.         lll = 0.5
  7.         mmm = 0.5
  8.         nnn = 0.5
  9.  
  10.         'For nr = 0 To 2
  11.         For ite = 0 To 20
  12.  
  13.             Dim Gauss As New GaussJ
  14.             Gauss.InpNumEq = 3
  15.  
  16.             Gauss.ManagMat(0, 0) = y(0, 0) - aux(2)
  17.             Gauss.ManagMat(0, 1) = y(0, 1)
  18.             Gauss.ManagMat(0, 2) = y(0, 2)
  19.             Gauss.ManagMat(1, 0) = y(1, 0)
  20.             Gauss.ManagMat(1, 1) = y(1, 1) - aux(2)
  21.             Gauss.ManagMat(1, 2) = y(1, 2)
  22.             Gauss.ManagMat(2, 0) = 2 * lll
  23.             Gauss.ManagMat(2, 1) = 2 * mmm
  24.             Gauss.ManagMat(2, 2) = 2 * nnn
  25.  
  26.             'f(l,m,n)
  27.  
  28.             ff = (y(0, 0) - aux(2)) * lll + y(0, 1) * mmm + y(0, 2) * nnn
  29.             gg = y(1, 0) + (y(1, 1) - aux(2)) + y(1, 2)
  30.             hh = lll ^ 2 + mmm ^ 2 + nnn ^ 2 - 1
  31.  
  32.             Gauss.ManagCons(0) = -ff
  33.             Gauss.ManagCons(1) = -gg
  34.             Gauss.ManagCons(2) = -hh
  35.  
  36.             Gauss.gaussj()
  37.             TextBox14.Text += Environment.NewLine
  38.             TextBox14.Text += "******x1= " & Format(Gauss.ManagCons(0), "0.0000")
  39.             TextBox14.Text += Environment.NewLine
  40.             TextBox14.Text += "******x2= " & Format(Gauss.ManagCons(1), "0.0000")
  41.             TextBox14.Text += Environment.NewLine
  42.             TextBox14.Text += "******x3= " & Format(Gauss.ManagCons(2), "0.0000")
  43.  
  44.             lll = Gauss.ManagCons(0) + lll
  45.             mmm = Gauss.ManagCons(1) + mmm
  46.             nnn = Gauss.ManagCons(2) + nnn
  47.  
  48.  
  49.             TextBox14.Text += Environment.NewLine
  50.             TextBox14.Text += Environment.NewLine
  51.             TextBox14.Text += "l=" & lll
  52.             TextBox14.Text += Environment.NewLine
  53.             TextBox14.Text += "m=" & mmm
  54.             TextBox14.Text += Environment.NewLine
  55.             TextBox14.Text += "n=" & nnn
  56.         Next ite
  57.         ' Next nr
  58.  
Good of you to add your code, spranto...

Not a mathematician, but in this case could explain a bit what newton raphson is and what it is supposed to do. Also, could you comment in English. This should help tackle the problem, especially if members here know what newton raphson is.

Sorry for your troubles!
May 25 '07 #2
kadghar
1,295 Recognized Expert Top Contributor
Hi,
I'm new here, but i've seen they dont like people to help others doing their homeworks. Anyway, i think you to use MatLab to make this with a matrix using Gauss Jordan.

Im not very familiarized with the gauss jordan functions in VB, but if your problem it's about a 3rd grade eq with NR, it could be easier to ask the user the function and the first d.

f(x) = Ax3 + Bx2 + Cx + D
f'(x) = Ex2 + Fx + G

and make the letters (A to G) the inputs for your function.

I saw you used a FOR to make 20 iterations, but i'd use a WHILE instead and some precision limit:

Public Function NR( A B... as Double) as Double

Dim Dou1 as Double '<----this is your precision
Dim Dou2 as Double '<--- this will be the value you obtain
Dim Dou3 as Double '<----this will be the former value you had

Dou1 = .000001
Dou2 = 0
Dou3 = .05

While Abs(Dou3 - Dou2) > Dou1
Dou3 = Dou2
Dou2 = Dou3 - (A*Dou3^3 + B*Dou3^2 + C*Dou3 + D) / ( E*Dou3^2 + F*Dou3^ + G)
Wend

NR = Dou2

End Function

Good Luck
May 29 '07 #3
Dököll
2,364 Recognized Expert Top Contributor
Hi,
I'm new here, but i've seen they dont like people to help others doing their homeworks. Anyway, i think you to use MatLab to make this with a matrix using Gauss Jordan.

Im not very familiarized with the gauss jordan functions in VB, but if your problem it's about a 3rd grade eq with NR, it could be easier to ask the user the function and the first d.

f(x) = Ax3 + Bx2 + Cx + D
f'(x) = Ex2 + Fx + G

and make the letters (A to G) the inputs for your function.

I saw you used a FOR to make 20 iterations, but i'd use a WHILE instead and some precision limit:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function NR( A  B...  as Double) as Double
  3.  
  4. Dim Dou1 as Double  '<----this is your precision
  5. Dim Dou2 as Double  '<--- this will be the value you obtain
  6. Dim Dou3 as Double  '<----this will be the former value you had
  7.  
  8. Dou1 = .000001
  9. Dou2 = 0
  10. Dou3 = .05
  11.  
  12. While Abs(Dou3 - Dou2) > Dou1
  13. Dou3 = Dou2
  14. Dou2 = Dou3 - (A*Dou3^3 + B*Dou3^2 + C*Dou3 + D) / ( E*Dou3^2 + F*Dou3^ + G)
  15. Wend
  16.  
  17. NR = Dou2
  18.  
  19. End Function
  20.  
  21.  
Good Luck
Hello, kadghar!

Nice of you to post you knowledge in this, again, I am blind here...hopefull y it is helpful to spranto:-)
May 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
16163
by: moi | last post by:
Can someone please help with this problem im having. i have to use the newton-raphson technique to find the root of a function, in this case X^2 - 1. basically, the program has to read in values of x0, tolerance, and a boolean as to whether the approximate or exact df/dx is to be used. and its specified that the function names and their signatures have to be as they are below. thats where im getting all buggered up really. i totally...
6
29319
by: sekitoleko | last post by:
c program for newton raphson algorithm for finding roots of a polynomial
2
7024
by: JamesUmokoro | last post by:
Please Im writing a project on mathematics here in school. Can someone help me with the source code for solving Numerical Analysis problem with Newton Raphson using Java programming? Thank you all...
11
9133
by: kartikegarg | last post by:
can you help me please with this problem.. i want a c program using newton raphson method for solving 18 equations... the equations are not of degree greater than 1... i need the program to input my 18 equations and give me the result
2
2471
by: kolnit | last post by:
Find a soln to the following eqtn by Newton-Raphson's method e^(0.05x)+x^2=132254 Let f(x)= e^(0.05x)+x^2-132254 perform iterations until abs f(x)<10^-6 I just have no idea wt to do!! THanks a lot!!
1
3009
by: dynamo | last post by:
Hi guys,i was wondering if anyone knows the code to solve equations using the newton raphson method in matlab.Or at least the algorithm.
10
8834
by: DDCane | last post by:
i have made a code for finding a derivative and now im trying to use it to help me with a code for the newton raphson method: def derivative (f,x,h): import math return float(1/(2*h)) * (f(x+h) - f(x-h)) def solve (f,x0,h): delta= f(x(n))/fp(x(n) for x(n+1) in solve(): x(n)-delta
2
2870
by: thiofdelux | last post by:
I need a c++ program that uses newton raphson method to find the rooys of a function. The program would prompt to put in the degree of the ploynomial, the error bound 10^(n), and the first approximation. Anybody please help if you can. i have been working on this for quite a while. Thanks
6
4552
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of the game is to find a zero of this function f (the point at which f crosses the x-axis). This zero-of-f which solves our problem is the double which NR returns. It remains to explain what the "double x" represents. This is the...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.