perl script to matlab code conversion

1 次查看(过去 30 天)
the following is the program that was converted from perl version to matlab. when executed in perl i got "pa" value around 9.81..but in matlab iam getting only 0.0763..can someone tel me y?..i need this answer badly pls
clc;
clear all;
j=1:6;
for i=0:length(j)
beta=2^i;
alow=0;
ahigh=10000;
pa=0;
r=3;
eps=0.1;
gminus=0;
gplus=0;
g=0;
fa=0;
while((ahigh-alow)>eps)
pa=(alow+ahigh)/2;
fa=1-(exp(-((((2^r)-1)/pa)^(beta/2))));
gminus=(((fa-1)/pa)*(pa-eps))+1;
glus=(((fa-1)/pa)*(pa+eps))+1;
fminus=1-(exp(-((((2^r)-1)/(pa-eps))^(beta/2))));
fplus=1-(exp(-((((2^r)-1)/(pa+eps))^(beta/2))));
if(((gminus<fminus)&&(gplus>fplus))==1)
alow=pa;
else
ahigh=pa;
end
disp(pa)
end
  4 个评论
Simon
Simon 2013-11-19
Hi!
It's not so easy to tell where the difference comes from if we only know the matlab code and not the perl code.
BTW, your code is missing an "end" at the end.
Walter Roberson
Walter Roberson 2013-11-19
The poster has indicated that this code was executed in perl. Which is not plausible, as perl requires $ or @ before each variable name (except sometimes for file handles.)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by