MATLAB: The following error occurred converting from sym to double: Unable to convert expression into double array.

diff()doubleMATLABsymbolicsyntax

R = 35.9; L = 3.98; C = 0.000360; P = ceil(R/(2*L));
M = ceil(sqrt( (1/(L*C)) - ( (R^2)/ (4*(L^2)) )));
phi_values = zeros(101, 2);
for ix = 1:101
phi_values(ix, 1) = cos(M * t);
end
I have no idea what is the problem

Best Answer

t is a symbolic variable instead it has to have doubles (numbers):
R = 35.9; L = 3.98; C = 0.000360; P = ceil(R/(2*L));
M = ceil(sqrt( (1/(L*C)) - ( (R^2)/ (4*(L^2)) )));
phi_values = zeros(101, 2);
t=linspace(0,pi,101); % define t this way
for ix = 1:numel(t)
phi_values(ix, 1) = cos(M * t(ix));
end
Without loop the same result can be obtained:
R = 35.9; L = 3.98; C = 0.000360; P = ceil(R/(2*L));
M = ceil(sqrt( (1/(L*C)) - ( (R^2)/ (4*(L^2)) )));
t=linspace(0,pi,101);
phi_values = (cos(M .* t)).';
Related Question