8 Replies - 263 Views - Last Post: 07 February 2012 - 12:26 PM Rate Topic: -----

Topic Sponsor:

#1 sokerfan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 10-July 11

I keep getting "Value" in the cell reserved for the solution.

Posted 07 February 2012 - 01:19 AM

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


Is This A Good Question/Topic? 0
  • +

Replies To: I keep getting "Value" in the cell reserved for the solution.

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 211
  • View blog
  • Posts: 1,249
  • Joined: 26-March 09

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.

This post has been edited by maj3091: 07 February 2012 - 01:24 AM

Was This Post Helpful? 1
  • +
  • -

#3 sokerfan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 10-July 11

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.
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 211
  • View blog
  • Posts: 1,249
  • Joined: 26-March 09

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.
Was This Post Helpful? 0
  • +
  • -

#5 sokerfan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 10-July 11

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.
Was This Post Helpful? 0
  • +
  • -

#6 sokerfan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 10-July 11

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.
Was This Post Helpful? 0
  • +
  • -

#7 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 211
  • View blog
  • Posts: 1,249
  • Joined: 26-March 09

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:

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

Was This Post Helpful? 0
  • +
  • -

#8 sokerfan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 10-July 11

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!
Was This Post Helpful? 0
  • +
  • -

#9 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 211
  • View blog
  • Posts: 1,249
  • Joined: 26-March 09

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1