how to convert contour plot from mathematica to matlab

183 views Asked by At

I am trying to draw a contour for an equation which I got from Mathematica. I was able to draw this contour easily in mathematica but not on matlab. Kindly suggest.

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)
1

There are 1 answers

1
A. Donda On BEST ANSWER

The thing to keep in mind is that Mathematica is formula-oriented and is programmed in terms of mathematical variables, while Matlab is numerically oriented and programmed in terms of matrices and arrays. To evaluate a function of two variables on a grid, it is necessary to first generate that grid explicitly in the form of arrays, and then to take care to use the element-wise operators (.*, ./ etc.) instead of the matrix operators. Here is the code:

[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)

I also took the liberty to slightly syntax-normalize and simplify your formula (e.g, power(2.718..., x) is exp(x)).

Here's the result:

enter image description here

If you want more contour lines, use something like contour(b, c, z, 100).

To understand what I've done here, read Array vs. Matrix operations and meshgrid from the Matlab documentation. Because .* means something else than * in Matlab, one should also take care not to have trailing decimal points in expressions, like 3.*B, though it doesn't really do any harm in that case.