When I try to run this code, this error message keeps showing up in matlab:
The expression to the left of the equals sign is not a valid target for an assignment.
a_k
and b_k
are meant to be row vectors of size (1,m)
. I can't use the command symsum
because it doesn't let me index these vectors within the symsum
. The resulting sum has to involve the dirac
and heaviside
functions. Ideas? :)
prompt = 'Enter m';
m = input(prompt);
prompt = 'Enter x-coordinates of dislocations';
a_k = input(prompt);
prompt = 'Enter y-coordinates of dislocations';
b_k = input(prompt);
syms x_1 x_2 y_1 y_2
F_1(y_1,y_2) = sum(heaviside(y_1-a_k(1,i))*dirac(1,y_2-b_k(1,i)), i=1:m);
You are using an invalid sum
syntax, i.e. i=1:m
.
sum
calculates the sum of all the elements in an array. So, you need to rewrite your formula in vectorised way using elementwise operations as follows:
F_1(y_1, y_2) = sum(heaviside(y_1-a_k(1,1:m)).*dirac(1,y_2-b_k(1,1:m)));