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 - The Fusion of Science and Community**

Dismiss Notice

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

Loading...

Similar Threads for Debugging equations vectorized | Date |
---|---|

MATLAB Sovling Bernoulli's differential equation in matlab? | Apr 3, 2018 |

Octave debug info randomly displayed | May 19, 2015 |

Debugging a FOURTH program 1992 era | May 7, 2009 |

Matlab debugging Aid. | Oct 4, 2004 |

**Physics Forums - The Fusion of Science and Community**