problems with symbolic calculations
이전 댓글 표시
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.
채택된 답변
추가 답변 (1개)
Trang Nguyen
2019년 7월 5일
0 개 추천
Thank you so much John D'Errico. It helps me a lot in my working. You are completely great. Thanks ^^
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!