gpt4 book ai didi

matlab - 如何绘制与其虚部相关的复杂系统

转载 作者:太空宇宙 更新时间:2023-11-03 19:27:37 25 4
gpt4 key购买 nike

我已经定义了复杂的符号系统:

syms x 
sys(x) = ((10+1.*i.*x))/(20+(5.*i.*x)+((10.*i.*x).^2))+((1.*i.*x).^3);
ImaginaryPart = imag(sys)
RealPart = real(sys)

MATLAB 返回了以下结果:

ImaginaryPart(x) =

- real(x^3) + imag((10 + x*1i)/(- 100*x^2 + x*5i + 20))


RealPart(x) =

- real(x^3) + imag((10 + x*1i)/(- 100*x^2 + x*5i + 20))

现在如何将 plot(x,sys(x))plot(x,ImaginaryPart(x)) 作为复曲面?

最佳答案

为了绘图,需要使用一系列值。因此,使用 x = a + b*i:

[a,b] = meshgrid(-10:0.1:10); %// creates two grids
ComplexValue = a+1i*b; %// get a single, complex valued grid
CompFun = @(x)(- real(x.^3) + imag((10 + x.*1i)./(- 100.*x.^2 + x.*5i + 20))); %// add dots for element wise calculation
result = CompFun(ComplexValue); %// get results
pcolor(a,b,result) %// plot
shading interp %// remove grid borders by interpolation
colorbar %// add colour scale
ylabel 'Imaginary unit'
xlabel 'Real unit'

enter image description here

我确实必须在你的等式中添加点(即元素明智的乘法)才能使其工作。

另外还有 contourf正如 comment by @AndrasDeak 中所建议的那样:

figure
contourf(a,b,result,51) %// plots with 51 contour levels
colorbar

我在这里使用了 -10:0.01:10 的网格以获得更高的分辨率:

enter image description here

如果您不愿意手动复制解决方案以添加元素明智的乘法点,您可以求助于循环:

grid = -10:0.1:10;
result(numel(grid),numel(grid))=0; %// initialise output grid
for a = 1:numel(grid)
for b = 1:numel(grid)
x = grid(a)+1i*grid(b);
result(a,b) = ImaginaryPart(x);
end
end

这会产生相同的结果,但各有利弊。它比矩阵乘法慢,即比在方程中加点慢,但它不需要手动操作输出。

关于matlab - 如何绘制与其虚部相关的复杂系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35243186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com