如何将等高线图从 Mathematica 转换为 Matlab

how to convert contour plot from mathematica to matlab

我正在尝试为从 Mathematica 获得的方程绘制等高线。我能够在 mathematica 中轻松绘制出这个轮廓,但在 matlab 中却不行。求推荐。

b=linspace(0.0005,0.0010,100);
c=linspace(0.64,0.7,100);

 z=(-136*power(2.718281828459045,power(88682,c)*b)*(1 - 1/power(2.718281828459045,1*power(88682,c)*b)))/(-1+ power(2.718281828459045,power(88682,c)*b)) - 1*(power(3,c) + power(33,c) + power(146,c) + power(227,c) + power(342,c) + power(351,c) + power(353,c) + power(444,c) + power(556,c) + power(571,c) + power(709,c) + power(759,c) + power(836,c) + power(860,c) + power(968,c) + power(1056,c) + power(1726,c) + power(1846,c) + power(1872,c) + power(1986,c) + power(2311,c) + power(2366,c) + power(2608,c) + power(2676,c) + power(3098,c) + power(3278,c) + power(3288,c) + power(4434,c) + power(5034,c) + power(5049,c) + power(5085,c) + 2*power(5089,c) + power(5097,c) + power(2,1. + 3.*c)*power(5287,c) + power(5324,c) + power(5389,c) + power(5565,c) + power(5623,c) + power(6080,c) + power(6380,c) + power(6477,c) + power(6740,c) + power(7192,c) + power(7447,c) + power(7644,c) + power(7837,c) + power(7843,c) + power(7922,c) + power(8738,c) + power(10089,c) + power(10237,c) + power(10258,c) + power(10491,c) + power(10625,c) + power(10982,c) + power(11175,c) + power(11411,c) + power(11442,c) + power(11811,c) + 2.*power(12559,c) + power(12791,c) + power(13121,c) + power(13486,c) + power(14708,c) + power(15251,c) + power(15261,c) + power(15277,c) + power(15806,c) + power(16185,c) + power(16229,c) + power(16358,c) + power(17168,c) + power(17458,c) + power(17758,c) + power(18287,c) + power(18568,c) + power(18728,c) + power(19556,c) + power(20567,c) + power(21012,c) + power(21308,c) + power(23063,c) + power(24127,c) + power(25910,c) + power(26770,c) + power(27753,c) + power(28460,c) + power(28493,c) + power(29361,c) + power(30085,c) + power(32408,c) + power(35338,c) + power(36799,c) + power(37642,c) + power(37654,c) + power(37915,c) + power(39715,c) + power(40580,c) + power(42015,c) + power(42045,c) + power(42188,c) + power(45406,c) + power(46653,c) + power(47596,c) + power(48296,c) + power(49171,c) + power(49416,c) + power(50145,c) + power(52042,c) + power(52489,c) + power(52875,c) + power(53321,c) + power(53443,c) + power(54433,c) + power(55381,c) + power(56463,c) + power(56485,c) + power(56560,c) + power(57042,c) + power(62551,c) + power(62651,c) + power(62661,c) + power(63732,c) + power(64103,c) + power(64893,c) + power(71043,c) + power(74364,c) + power(75409,c) + power(76057,c) + power(81542,c) + power(82702,c) + power(84566,c) + power(88682,c))*b + 1266.5546418385234*(-1 + c) + 136.*log((136.*power(2.718281828459045,power(88682,c)*b))/(-1 + power(2.718281828459045,power(88682,c)*b))) + 136*log(b) + 136*log(c);
 contour(b,c,z)

要记住的是,Mathematica 是面向公式的,根据数学变量进行编程,而 Matlab 是面向数值的,根据矩阵和数组进行编程。要在网格上评估两个变量的函数,首先需要以数组的形式显式生成该网格,然后注意使用元素运算符 (.*./等)而不是矩阵运算符。这是代码:

[B, C] = meshgrid(b, c);

z = (-136*exp(power(88682,C) .* B) .* (1 - 1./exp(1*power(88682,C) .* B)))./(-1+ exp(power(88682,C) .* B)) ...
- 1*(power(3,C) + power(33,C) + power(146,C) + power(227,C) + power(342,C) + power(351,C) + power(353,C) + power(444,C) + power(556,C) + power(571,C) + power(709,C) + power(759,C) + power(836,C) + power(860,C) + power(968,C) + power(1056,C) + power(1726,C) + power(1846,C) + power(1872,C) + power(1986,C) + power(2311,C) + power(2366,C) + power(2608,C) + power(2676,C) + power(3098,C) + power(3278,C) + power(3288,C) + power(4434,C) + power(5034,C) + power(5049,C) + power(5085,C) + 2*power(5089,C) + power(5097,C) + power(2,1 + 3*C) .* power(5287,C) + power(5324,C) + power(5389,C) + power(5565,C) + power(5623,C) + power(6080,C) + power(6380,C) + power(6477,C) + power(6740,C) + power(7192,C) + power(7447,C) + power(7644,C) + power(7837,C) + power(7843,C) + power(7922,C) + power(8738,C) + power(10089,C) + power(10237,C) + power(10258,C) + power(10491,C) + power(10625,C) + power(10982,C) + power(11175,C) + power(11411,C) + power(11442,C) + power(11811,C) + 2*power(12559,C) + power(12791,C) + power(13121,C) + power(13486,C) + power(14708,C) + power(15251,C) + power(15261,C) + power(15277,C) + power(15806,C) + power(16185,C) + power(16229,C) + power(16358,C) + power(17168,C) + power(17458,C) + power(17758,C) + power(18287,C) + power(18568,C) + power(18728,C) + power(19556,C) + power(20567,C) + power(21012,C) + power(21308,C) + power(23063,C) + power(24127,C) + power(25910,C) + power(26770,C) + power(27753,C) + power(28460,C) + power(28493,C) + power(29361,C) + power(30085,C) + power(32408,C) + power(35338,C) + power(36799,C) + power(37642,C) + power(37654,C) + power(37915,C) + power(39715,C) + power(40580,C) + power(42015,C) + power(42045,C) + power(42188,C) + power(45406,C) + power(46653,C) + power(47596,C) + power(48296,C) + power(49171,C) + power(49416,C) + power(50145,C) + power(52042,C) + power(52489,C) + power(52875,C) + power(53321,C) + power(53443,C) + power(54433,C) + power(55381,C) + power(56463,C) + power(56485,C) + power(56560,C) + power(57042,C) + power(62551,C) + power(62651,C) + power(62661,C) + power(63732,C) + power(64103,C) + power(64893,C) + power(71043,C) + power(74364,C) + power(75409,C) + power(76057,C) + power(81542,C) + power(82702,C) + power(84566,C) + power(88682,C)) .* B ...
+ 1266.5546418385234*(-1 + C) + 136*log((136*exp(power(88682,C) .* B))./(-1 + exp(power(88682,C) .* B))) + 136*log(B) + 136*log(C);
contour(b, c, z)

我还冒昧地对您的公式进行了语法规范化和简化(例如,power(2.718..., x)exp(x))。

结果如下:

如果你想要更多的等高线,使用类似contour(b, c, z, 100)的东西。

要了解我在这里所做的工作,请阅读 Matlab 文档中的 Array vs. Matrix operations and meshgrid。因为 .* 在 Matlab 中意味着不同于 * 的其他含义,所以还应该注意不要在表达式中包含尾随小数点,例如 3.*B,尽管它并没有真正造成任何伤害案例.