Skip to main content

Posts

Python - Nelder Mead vs fsolve: pH equilibria optimization problem leads to numerical instability in Nelder Mead?

I'm creating a pH equilibrium calculator - starting with initial compositions of certain acids / bases the calculator should come up with the equilibrated concentrations of each component based on physical constants. I've formulated this as a set of equations which need to be solved simultaneously. One key constraint is that H_plus*OH_minus must be 10^-14 , and I've included this in the equations. Code #1: Fsolve. This works, but is sensitive to initial conditions, and I can't put constraints (I need concentrations to be >=0). import numpy as np from scipy.optimize import fsolve def equations(variables, Ka, Kw, initial_concentrations): HA, A_minus, H_plus, OH_minus, ion_Na = variables HA_init, A_minus_init, H_plus_init, OH_minus_init, ion_Na_init = initial_concentrations # Define the equations eq1 = HA + A_minus - HA_init - A_minus_init # Mass balance on acetate eq2 = H_plus + ion_Na - OH_minus - A_minus # charge balance eq3 = H_plus *...

getting "module not found" error when the library is in the anaconda3/envs/projects_env folder

i installed python's schedule library in anaconda, the path is like this: /anaconda3/envs/myprojectenv/schedule my python3 project is in a separate folder, the path is like this: /Desktop/projects/myproject.py when i activate the anaconda3 environment and run my python project, it can't find the schedule library. do the python libraries & packages i install for use in a project need to be in the same directory as that project? because right now i only have it in my anaconda3 environment folder and it can't seem to find it, even with the environment activated. source https://stackoverflow.com/questions/77208273/getting-module-not-found-error-when-the-library-is-in-the-anaconda3-envs-proje

Iterating through

I'm trying to iterate through all of the <ng-template> generated HTML elements and adding event listeners to it and adding/removing classes, but as I'm iterating through the elements it's not letting me grab the actual element. Therefore, I can't grab stuff like classList or innerHTML This is what the console throws: ERROR TypeError: item.classList is undefined Here is my Template Code: <div class="nav-container"> <h2 class="fw-semibold text-center pt-3 logo">bytenotes</h2> <button class="newCat-btn">+ New Category</button> <nav #catItem class="navbar-container"> <h3 *ngFor="let category of categories; first as firstCat" class="catItem" [ngClass]="firstCat ? 'active' : ''" > </h3> </nav> </div> Here is my Component Code: @Component({ selector: 'app-nav', tem...

How to make text field visible based on a specific dropdown list value?

I have a list of option values. Only when a certain option from the value is selected and I would like to show custon_25 text field. I select a specific option like value 2, 5 or 7 then show the text field to enter. Can anyone help please? Thanks $('#select2-results').click('change',function() { if($('value==2').is(':selected')) { $('#custom_25').show(); } else { if($('#custom_25').is(':visible')) { $('#custom_25').hide(); } } }); <div id="editrow-custom_24" class="crm-section editrow_custom_24-section form-item" style="display: block;"> <div class="label" style="display: none;"> <label for="custom_24">Medical Service</label> </div> <div class="edit-value content"> <div class="select2-container crm-select2 crm-form-select select2-allowclear" id="s2i...

The js seems like stop working when I switch to another tab on browser, is a problem?

I made a clock. I realized that when I switch another tab and came back after a while the clock stop behind current time. I found something named web workers, is it related to this?? Same senteces, don't read. I made a clock. I realized that when I switch another tab and came back after a while the clock stop behind current time. I found something named web workers, is it related to this?? I expected the code work anytime but it didn't. The code: let numbers = document.getElementsByClassName('number'); let numbersLength = numbers.length-1; let numberContainer = document.querySelectorAll('.number > div'); let minute = document.querySelector('#minute'); let hour = document.querySelector('#hour'); let second = document.querySelector('#second'); let startSecond = new Date().getSeconds()*6; let startHour = new Date().getHours()*30; let startMinute = new Date().getMinutes()*6; setInterval(increaseSecond, 1000); function readyHour() {...

Table Jquery Horizontal Scroll on Click

I have a table with overflow scroll and I'd like the user to be able to click a button to scroll the table as well. Please see fiddle below for my code. Any help on where i'm going wrong would be greatly appreciated. I have a fiddle here Via Active questions tagged javascript - Stack Overflow https://ift.tt/hzQUbVL

How to live video stream using node API (Read file with chunk logic)

I want to make a live video streaming API and send the video buffer chunk data to an HTML. I am using rtsp URL. The chunk logic does not work. The video only plays for 5 seconds then stops. index.js file const express = require('express'); const ffmpeg = require('fluent-ffmpeg'); const fs = require('fs'); const path = require('path'); const app = express(); const port = 3000; app.get('/', (req, res) => { res.sendFile(__dirname + "/index.html"); }); const rtspUrl = 'rtsp://zephyr.rtsp.stream/movie?streamKey=64fd08123635440e7adc17ba31de2036'; const chunkDuration = 5; // Duration of each chunk in seconds app.get('/video', (req, res) => { const outputDirectory = path.join(__dirname, 'chunks'); if (!fs.existsSync(outputDirectory)) { fs.mkdirSync(outputDirectory); } const startTime = new Date().getTime(); const outputFileName = `chunk_${startTime}.mp4`; const outputFilePath = path.join(...