I get different results from these two functions. I need a fresh pair of eyes to help me find the discrepancy. The old way I did it, with the for-loop, gave proper results (but is slower, I think).(adsbygoogle = window.adsbygoogle || []).push({});

VECTORIZED (wrong):

vectorized result:Code (Text):

Nss = .5*(1+tanh((y(1,:)-V3)/V4)); %N as t --> inf

tau = 1./(phi*cosh((y(1,:)-V3)./(2*V4)));

dy(:,2) = (Nss-y(2,:))./tau;

a4 = (Nss(1)-y(2,1))./tau(1);

save newodeset a4

a4 = 0.5300

FOR-LOOP (right):

for-loop result:Code (Text):Nss = .5*(1+tanh((y(1)-V3)/V4)); %N as t --> inf

tau = 1/(phi*cosh((y(1)-V3)/(2*V4)));

dy(2) = (Nss-y(2))/tau;

a4 = a4 = (Nss-y(2))/tau;

a4 = 0.4572

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Debugging equations. vectorized vs. for-loop

**Physics Forums | Science Articles, Homework Help, Discussion**