Option Explicit Function Bisection(xl, xu, es) Dim xold As Double, xr As Double If func(xl) * func(xu) >= 0 Then MsgBox "No sign change!" Exit Function End If Do xold = xr xr = (xl + xu) / 2 If func(xr) = 0 Then Exit Do If func(xr) * func(xl) < 0 Then xu = xr Else xl = xr End If If xr <> 0 Then If Abs((xr - xold) / xr) * 100 < es Then Exit Do End If Else xold = xr End If Loop Bisection = xr End Function Function func(x) func = x ^ 3 + 4 * x ^ 2 - 10 End Function
8 Replies - 263 Views - Last Post: 07 February 2012 - 12:26 PM
Topic Sponsor:
#1
I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 01:19 AM
Replies To: I keep getting "Value" in the cell reserved for the solution.
#2
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 01:24 AM
You could have edited the original post, you didn't need to create a new one.
You need to provide a little more information.
Based on your error, it sounds as though this is related to Excel, is that correct?
Also, with your functions, why don't they have a datatype associated with them? Is that by design?
Give us a little more insight as to what you're doing and what you're trying to achieve. Thanks.
You need to provide a little more information.
Based on your error, it sounds as though this is related to Excel, is that correct?
Also, with your functions, why don't they have a datatype associated with them? Is that by design?
Give us a little more insight as to what you're doing and what you're trying to achieve. Thanks.
This post has been edited by maj3091: 07 February 2012 - 01:24 AM
#3
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 01:30 AM
You are correct. The user enters the values for xl, xu, es in an excel spreadsheet, and
the program should give an answer (root). They did not ask to use Datatype for the fucnctions.
the program should give an answer (root). They did not ask to use Datatype for the fucnctions.
#4
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 01:51 AM
I don't see any reference to Cells in your code, which suggests that you're not directly writing the output to a cell from the code you've posted.
So I'm guessing that this error might occur in how you're calling this function, as opposed to being function related.
How are you calling the function, is it directly from a cell where you want the answer to be display?
Can you show the code that you call the function with please.
So I'm guessing that this error might occur in how you're calling this function, as opposed to being function related.
How are you calling the function, is it directly from a cell where you want the answer to be display?
Can you show the code that you call the function with please.
#5
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 01:58 AM
Of course,
I choose a random cell, and put for example = Bisection(-5,9,0.005)
I press enter, and I get "name" instead of a number.
I choose a random cell, and put for example = Bisection(-5,9,0.005)
I press enter, and I get "name" instead of a number.
#6
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 02:09 AM
ok it's 3 am ..I'm going night night thank you anyway brother.
I'll get back to it when I wake up.
I'll get back to it when I wake up.
#7
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 02:10 AM
Try changing your function declaration, as it's using everything as variants.
Change it to something like below, so it knows that you're passing numbers and it's set to return a number:
Also, do the same with the Func function.
at least this way, you're telling the system you're working with numbers.
Also, what format is the cell?
Change it to something like below, so it knows that you're passing numbers and it's set to return a number:
Quote
Function BiSection(xl as double, xu as double, es as double) as double
Also, do the same with the Func function.
at least this way, you're telling the system you're working with numbers.
Also, what format is the cell?
This post has been edited by maj3091: 07 February 2012 - 02:13 AM
#8
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 11:12 AM
It finally worked, I am having the results I wanted. I have tried different functions and it worked every time. Thank you again!
#9
Re: I keep getting "Value" in the cell reserved for the solution.
Posted 07 February 2012 - 12:26 PM
Glad you got it sorted, but for the benefit of others that may visit this post in future, can you post back what you did to solve the problem, that way, if anyone else if having similar issue, they have a proven solution to work with.
Thanks.
Thanks.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|