overflow in exp, python

2024/11/18 22:59:43

can't really figure out why this error RuntimeWarning: overflow encountered in exp is showing up. The function I'm trying to implement is:

Id = lambda t_u, yp: Is * (np.exp((Vin(t_u) - L*yp)/(n_Ut*Ut)) - 1.0)

with values:

Vin = lambda t: Vo * np.sin(2*np.pi*w*t)L = 50e-3  # 50 mH
Vo = 5  # 5 V
w = 50  # 50 Hz
Is = 1e-9   # 1 nA
Ut = 25e-3  # 25 mV
n_Ut = 1.0

The function Id is part of a ODE that I'm trying to solve with Runge-Kutta-Method.

EDIT:

Methoden\Serien\6>python circuit.py
Traceback (most recent call last):File "circuit.py", line 148, in <module>perform_experiment(exrk_o5(), "exrk_o5")File "circuit.py", line 48, in perform_experimentt, y = run_method(method, label)File "circuit.py", line 69, in run_methodt, y = method.__call__(circuit_rhs, y[0, :], t_end, n_steps)File "C:\Users\-\numerical_methodes\6\rk.py", line 49, in __call__t[k+1],y[k+1, :] = self.step(f, y[k, :], t[k], dt)File "C:\Users\-\numerical_methodes\6\rk.py", line 102, in stepdydt[:, i] = rhs(t + c[i] * dt, y0 + dt * np.dot(A[i, :].T, dydt.T))File "circuit.py", line 38, in circuit_rhsdydt=  np.array ([y[1] , Id(t, y [1]) /(C*L) - y [1]/( R*C) - y [0]/( C*L)])File "circuit.py", line 27, in <lambda>Id = lambda t_u, yp: Is * (np.exp((Vin(t_u) - L*yp)/(n_Ut*Ut)) - 1.0)
FloatingPointError: overflow encountered in exp

where y[1]=0 and y[0]=0, as first values. The rk.py file is just the implementation of the Runge-Kutta-Method.

Answer

Vin can return a value as high as 1.0; then you subtract something, resulting in an utterly unknown quantity. You multiply that by 40, subtract 1, and raise epsilon to that power. Depending on the value of yp, there's plenty of room for overflow in this process. A sufficiently negative value for yp will cause the problem without reference to intermediate computations.

numpy.exp(n) overflows for some value in the range 700-800. This suggests that yp is perhaps <= -350.

https://en.xdnf.cn/q/120018.html

Related Q&A

Getting a matlab codes results on python

I have code in matlab whose results I would like to use in python code (as a matrix or as a .dat file). Could anyone tell me how this could be done?

My Status object is not saving in Django

When I enter the shell, I run into the following problem:from users.models import Status from django.utils import timezoneStatus.objects.all() >>> [] p = Status() p.status_time = timezone.date…

Too many instances are running for Django Server

When Django server gets started, I can see only one instance of Django server running in the background. But after a while, I can see multiple instances are running.Output:root@GoldenGate:~# ps |grep p…

Not able to display images from static folder using Django

This is my home.html Im not able to display the images in static/images/ folder. Although *[09/Mar/2020 15:52:09] "GET /static/images/mona.jpg HTTP/1.1" 404 1669 * is displayed in terminal.&l…

Regex to match phone number 5ABCDYYZZ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 1 year ago.Improve …

Remove an \\n\\t\\t\\t-element from list

I got the following list called "phonenumbers". I struggle to remove the elements which contain \n\t\t\t and \n\t\t\t\t. I tried "try and except"-methode and remove(\n\t\t\t\t) but …

Find all numbers in a string in Python 3 [duplicate]

This question already has answers here:How to extract numbers from a string in Python?(20 answers)Split Strings into words with multiple word boundary delimiters(31 answers)Closed 8 years ago.Newbie h…

call dictionary from one function to another

How can I call a dictionary created in one function to another?I have tried using How do I access a dictionary from a function to be used in another function? but it doesnt work for me.I have created…

How to change values in numpy array

import numpy as np a=np.array([[4,2,6],[3,6,5]]) b=np.array([3,5])I want to update the numbers in "a" which are bigger than the numbers in "b" to np.nan. If they are smaller or equa…

Why use the object oriented approach in matplotlib for visualizing data? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…