r/learnpython • u/Current_Beginning_39 • 52m ago
How to solve python problems?
This may be a dumb questions, but I do not get how to write code. For some context, I am taking a scientific computing course in my uni, I am a physics major, so most of the coding we do pertains to some kinda physics/math related problem. I know how to do the math on its own but I don't get how to translate it into code. When I see a problem I don't even know how to start it.
For example:
Write a function my_cubic_spline_flat(x, y, X), where x and y are arrays containing experimental data points, and X is an array. Assume that x and X are in ascending order and have unique elements. The output argument, Y, should be an array, the same size as X, where Y[i] is the cubic spline interpolation of X[i]. However, instead of the constraints we introduced before, 𝑆′1(𝑥_1)=0 and 𝑆′𝑛−1(𝑥_𝑛)=0.
When I see that, I do not know what to do. Like I know how to write functions and stuff, but not the actual code that goes inside the function.
Any advice is appreciated! :)
View all comments
Show parent comment
•
u/JaguarMammoth6231 16m ago
Can you write a function that takes an input array and returns an output array of the same size with each value being the square of the corresponding input value?
If not, can you make a function that returns an array of size 10 with all entries being 0.0 except entry 2 is 7.0?