Message Boards Message Boards

0
|
6047 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Iterative method for a simple function

Take the function

V = 10 (1-Exp[-0.1 t])

I want to program a code that will give me this function as

     t=t+tau
     V=V+D[V,t] tau 

via an iterative method for say tau=0.01 and I=1 to 1000. This seems simple but I have so far had little success. I would like to be able to plot the results of this computation.

POSTED BY: Ray Sjodin
5 Replies

I just tried your code and found it to work well. Thanks.,Ray

POSTED BY: Ray Sjodin

Hi Bill, I will try your code .Thanks again. I have produced a code that does work. It goes as follows:

Clear[t,V], V=10 (1-Exp[-.1 t]) ,D[V,t]=Exp[-.1 t],t=0,V=0,points={t,V}

then

  points=Table [t=t+.01; V=V+Exp[-.1 t] .01,{I,1,5000}],  ListPlot[points]

My success has probably given me some false confidence! I am happy to try your code as well, Regards, Ray

POSTED BY: Ray Sjodin
Posted 9 years ago

See if you can put this into your Mathematica and run it without error.

Clear[t];
tau = .1;
V[t_] := 10 (1 - Exp[-0.1 t]);
dV = D[V[t], t];
v = 0;
points = Table[{time, v = v + dV /. t -> time}, {time, 0., 10, tau}];
ListPlot[points]

I may not have understood exactly the function you wished to create. If this code does not do what you need then perhaps you can modify it or you can try to explain your question in another way and I will see if I can modify this for you.

POSTED BY: Bill Simpson

Thanks for reply. I put in what I thought to be your code and it did not work.

Dear Bill,

I put in what I thought to be your code suggestion and found that this did not work. I do not know much about programming and would have to see a detailed code that works, Then I could analyze and try to understand it. If you can provide this, I would be grateful. If not, thanks anyway,,Ray

POSTED BY: Ray Sjodin
Posted 9 years ago

It seems like you are using several of your variable names for more than one thing. That may confuse Mathematica.

Can you see if you can understand this idea and perhaps adapt it to what you want to do?

Clear[t];(*Make sure t has no assigned value*)
V[t_] := 10 (1 - Exp[-0.1 t]);(*Define V function of t*)
dV = D[V[t], t];(*Define derivative of V at any t*)
v = 0;(*Start the iteration value with v=0*)
(*Now create a list of {time,v} values where t is replaced with time in dV*)
points = Table[{time, v = v + dV /. t -> time}, {time, 0., 10, tau}]

That tries to use the function V[t] for only that purpose, the derivative dV for only that purpose, the iteration time for only that purpose and the iteration value for only that purpose.

Then you can plot the result using this

ListPlot[points]

If I have misunderstood and you can explain then perhaps I will be able to correct this for you

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract