![]() |
|
#1
|
|||
|
|||
Powell MethodHey all Im trying to write a program using powells method to minimize a polynomial. Im fairly new so any help would be greatly appreciated. Thanks
CPP / C++ / C Code:
Last edited by admin : 30-Sep-2005 at 23:55.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
|||
|
|||
Re: Powell MethodQuote:
So: what is your question? (Saying, "I'm trying to write a program," isn't really a question is it?) What would you like us to do? Have you tried to compile your code? If you are really new, then I would respectfully suggest you learn fundamentals with simple functions before getting into some numerical analysis that might be more difficult to debug. You don't have to waste time writing throw-away stuff (like, for example, writing a function that takes two numbers and returns the sum of the numbers), but for real beginners, maybe that's not a bad way to learn fundamentals of functions and how they are used in C. You can take your functions (the simple ones), write and test them one at a time. For example, here is a testbed for your func(): CPP / C++ / C Code:
Now test this. Does it compile? Do you get any warnings or errors? Do you understand what the compiler is telling you? Can you execute the program? If you have any problems, then show what you got, and tell us what you expected to get and tell us what you don't understand. (You might also mention what compiler/Operating System you are using; sometimes it makes a difference to people trying to help.) If you get this function to work OK for x = 1, try other values of x (or use cin>> to get values from the user). Then on to the next. Regards, Dave |
|
#3
|
|||
|
|||
Re: Powell MethodThank you for your reply. I am using Dev-C++ compiler. I need a function where if I press any key it will proceed to the next action. Also, for some reason it wont even let me define x3. The else function looks fine to me.
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Powell MethodQuote:
I hate to repeat myself but: Quote:
When you say, "It won't even let me define x3," I assume that you got an error message somewhere. Where? You have lots of lines with x3. Which one gave the error message? On the other hand, I don't intend to go through 139 lines of code and probably 50 or so error/warning messages for you. Try to understand that I'm not just trying to give you a hard time, I am trying to make the point that You (yes, You) are the best resource for debugging. People on this Forum are here trying to help. Most of us feel that the best way to help is to get you to ask the right question(s) and then we will try to help you understand the answer(s). The way I tried to help is this: Quote:
If you don't want to start with the particular function of yours that I gave as an example, then pick another. If you want to go on floundering with many many lines of code that you don't understand, well I can't think of anything else to say. So, here's one more attempt at showing an approach that is more likely to get some progress for you: Write a short main() program that tests one function. If you get any errors or warnings that you don't understand then: 1. Post the exact complete code that you tested. 2. Post the exact error/warning messages that you don't understand (copy/paste them into your post; don't paraphrase). Regards, Dave |
|
#5
|
|||
|
|||
Re: Powell MethodHey David, thanks for the help. I cleaned up the code a bit and reduced my errors to roughly 15 compared to about 50 to begin with. I attached the error log. The errors that I cant seem to understand are as follows.
Initially, I cant get my F(x3) to compute, CPP / C++ / C Code:
(the value "2" stands for deltax*1 but since I wont be using any thing other than 1 for delta x im keeping it simple) Secondly, My fmin function will not work: CPP / C++ / C Code:
This seems right to me and causing me much frustration. Any ideas? Thanks, David Last edited by LuciWiz : 01-Oct-2005 at 07:49.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#6
|
|||
|
|||
Re: Powell MethodQuote:
Quote:
What do you mean "will not work"? What values did you give it? What values did it return? I don't see how I can help you understand if I don't know what you don't understand. Your first error message is about line 31, and is in function powell(). The code snippets that you post don't show me whether they are part of function powell(). Other error messages are talking about xopt() I don't see any xopt() in the code of this post. I seem to remember a function called xopt() in a previous post, but I have no idea where it is in the code that you are asking about now. There is no point in my trying to guess what you are currently working with. If you want to compile xopt() by itself along with a test version of a main() program that calls the function, and you want to understand what's wrong, then post that code (and only that code) along with its error messages or other unexpected behavior. If you insist on trying to compile a whole bunch of incorrect code without understanding the very first thing, then I can't help you. I have suggested twice how I would approach the problem. If you don't want to do it that way, that's OK, but I simply am out of ideas how to help. Maybe someone else on this forum can jump in where I have failed. In order to help the next helper, I respectfully suggest that you do the following: If you want to test fmin(), then 1. Write a short main() that calls fmin() with various values of arguments and prints out the value returned from fmin() each time. 2. Make a file that has only fmin() and main(). Compile and execute. If the compiler gives you error messages, post the exact error messages along with the complete code. Maybe someone can help you understand. If your test program compiles OK, but doesn't give the results that you expect: 1. Post the exact code that you are testing --- everything, not just part. 2. Post the exact input that you gave and the output that you get. 3. Tell the person trying to help you what you expected to get and what you don't understand about what you got. I am really sorry I couldn't help. Sometimes I nail it, and sometimes --- not so much. Regards, Dave (Over and Out) |
Recent GIDBlog
Developing GUIs with wxPython (Part 4) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Non-member method needs info from class... how? | Elsydeon | C++ Forum | 3 | 19-Sep-2005 15:13 |
| TextBox->RefreshText () method??? | richiemac | .NET Forum | 3 | 23-May-2005 02:29 |
| Simulation - Composition method | wu_weidong | C Programming Language | 7 | 13-Mar-2005 09:05 |
| calling abstract base class method calls draw instead | achoo | FLTK Forum | 1 | 19-Dec-2004 09:38 |
| regarding main method | jerry | C++ Forum | 18 | 09-Mar-2004 18:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The