problems with symbolic calculations
Show older comments
Hi, I'm getting an error while trying to do a calculation with a symbolic expression.
First I'll write the code so I can explain my question.
Earlier in the code I defined what the variable n is, n is a cell of size 2x1 where:
n{1}
is a symbolic expression with symbolic variable x and
n{2}
is the second symbolic expression with variable x.
Also the variable L has been defined before in the code, to simplify let's suppose that
L = [2 3];
Likewise the variable c has been defined before like this:
%Physical constants definition
c = 299792458; %Speed of light in [m/s] , needs to be converted to micrometer.
c = c.*10^6; %Conversion to micrometers.
Then my problem arises when I try to do the following calculations:
d = length(n);
t1 = zeros(1,d);
for i=1:d
t1(i) = n{i}.*L(i)./c;
end
Then I get the following error from matlab:
The following error occurred converting from sym to double:
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use VPA.
I have allready tried to use vpa like this:
for i=1:d
t1(i) = vpa(n{i}.*L(i)./c);
end
but I get the same error.
Can someone tell me how to avoid this error and be able to complete the calculations?
Thanks in advance for the effort and time.
Accepted Answer
More Answers (1)
Trang Nguyen
on 5 Jul 2019
0 votes
Thank you so much John D'Errico. It helps me a lot in my working. You are completely great. Thanks ^^
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!