我正在尝试解决一维非线性泊松方程(电荷分布取决于电位)。我一直将它视为最小化问题,并且一直在使用scipy.optimize模块中的fsolve函数。
虽然定性地得到了一个合理的答案,但我注意到它随着阵列中各点之间的距离而变化。这是合理的,因为解决方案(及其衍生物)是指数的。解决方案,如果最受影响的是在定义问题的空间边界附近。
“fsolve”完成计算所需的时间似乎随着数组中的点数而急剧增加。我一直在寻找在numpy的'logspace'函数的帮助下使用非线性间距的选项。但是,此功能仅在阵列的一侧提供更紧密的间距。我一直在尝试使用'logspace'生成两个数组并连接它们但是没有设法获得所需的结果。
为了澄清,我需要一个范围为[0,x]的数组(x是一些浮点值),其中数组点之间的间距随着接近0或x而变小。有关如何实现这一目标的任何建议吗?
答案 0 :(得分:2)
以下应该为您提供0到1之间的对数刻度间距,因此您可以根据需要进行缩放。我已经包含了两个解决方案,包括和没有边界值。
// Create the image from a png file
UIImage *image = [UIImage imageNamed:@"myImage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// Get size of current image
CGSize size = [image size];
// Frame location in view to show original image
[imageView setFrame:CGRectMake(0, 0, size.width, size.height)];
[[self view] addSubview:imageView];
// Create rectangle that represents a cropped image
// from the middle of the existing image
CGRect rect = CGRectMake(size.width / 4, size.height / 4 ,
(size.width / 2), (size.height / 2));
// Create bitmap image from original image data,
// using rectangle to specify desired crop area
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *img = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// Create and show the new image from bitmap data
imageView = [[UIImageView alloc] initWithImage:img];
[imageView setFrame:CGRectMake(0, 200, (size.width / 2), (size.height / 2))];
[[self view] addSubview:imageView];