Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab and arrays [closed]

Tags:

matlab

I have a code like this:

t = a:(b-a)/10:b;
y = myFunction(t);

As far as I guess, this code creates an array t, and another array y by applying each value of t to myFunction.

However, if I manually pass the first element of array t to myFunction like this

y = myFunction(t);

I will not get the first element of y but a different number. Why?

P.S.
myFunction looks like this:

function res = myFunction(x)
    res = tanh(5*x.^2 + 3*x - 2) + exp((x.^3 + 6*x.^2 + 12*x + 8)/(2*x.^2 + 8*x + 7))-2.0;
end
like image 917
a3dsfcv Avatar asked Jan 14 '13 18:01

a3dsfcv


1 Answers

In myFunction you are performing a right matrix divide (using /) whereas you intend to use element-wise divide (using ./).

like image 94
Chris Taylor Avatar answered Oct 12 '22 01:10

Chris Taylor