Suppose I have a function y (t, x) = exp (-t) * sin (x)
In matlab, I define
t = [0: 0.5: 5]; x = [0: 0.1: 10*2*pi]; y = zeros(length(t), length(x)); % empty matrix init
Now, how do I determine the matrix y without using any loop , so that each element y (i, j) contains the value of the desired function y at (t(i), x(j)) ? The following shows how I did this using a for loop.
for i = 1:length(t) y(i,:) = exp(-t(i)) .* sin(x); end
vectorization matrix matlab
Aamir
source share