Help on User Defined Function

xc405

Board Regular
Joined
Jul 2, 2011
Messages
54
I have created a function that calculates a final velocity of a skydiver:

Code:
Function David(vi, g, c, m, tf, ti, dt)
    n = (tf - ti) / dt
    v = vi
    t = ti
For i = 1 To n
    v = v + (g - (c / m) * v) * dt
Next i
    David = v
End Function

Now i want the function to automatically use c=50 once t=10 seconds.
Does anyone know?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
This is your function adding a time increment and if statement to change c when t >= 10 secs

Code:
Function David(vi, g, c, m, tf, ti, dt)
    n = (tf - ti) / dt
    v = vi
    t = ti
For i = 1 To n
    If t >= 10 Then c = 50
    v = v + (g - (c / m) * v) * dt
    t = t + dt
Next i
    David = v
End Function
 
Upvote 0
It doesn't work, it gives me an answer of 20 and it should be much higher. I took away the time step and I got 15.68 so I'm
Not sure if it's working right. Thanks for the help though.
 
Upvote 0
I didn't check the physics of your problem I just provided the code required to change c at time = 10. It been a while since my first semester of physics where we covered this sort of problem so could you link to or otherwise reference the equation you are using. There is also the question of terminal velocity.

The input used in the function and the expected result would also helpful. Saying it's returning 20 doesn't mean much I don't even know what units you are using.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top