Symbol to double error, 0x0 syms

am trying to solve a variable in an equation (syms x), I've simplified the equation. I am trying to store the value in P_9, a 1x1000 matrix by converting from a symbol to a double and am getting the error below. It is giving me a symbol of 0x0, which is where I think my error lies.
Please help me troubleshoot my code. Many thanks!
L
number = 1000;
P_9 = zeros(1,number);
A_t=0.67;
A_e = linspace(0,10,number);
for n=1:number
%%find p9
syms x
eqn = x + 5 ==A_t/A_e(n);
solx = solve(eqn,x);
P_9(n) = double(solx);
end
Warning: Explicit solution could not be found.
In solve at 179 In HW4 at 74 In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in HW4 (line 76) P_9(n) = double(solx);

Answers (1)

You need to assign a numeric value when a solution is not found. Your array has to have a numeric value for each element of it in order to process. Therefore, your code can be modified as follows:
number = 1000;
P_9 = zeros(1,number);
A_t=0.67;
A_e = linspace(0,10,number);
for n=1:number
%%find p9
syms x
eqn = x + 5 ==A_t/A_e(n);
if isempty(double(solve(eqn,x)))
P_9(n)=0;
else
P_9(n)=double(solve(eqn,x));
end
end

1 Comment

number = 1000;
P_9 = zeros(1,number);
A_t=0.67;
A_e = linspace(0,10,number);
for n=1:number
%%find p9
syms x
eqn = x + 5 ==A_t/A_e(n);
thisP9 = solve(eqn,x);
if isempty(thisP9)
P_9(n)=0;
else
P_9(n)=double(thisP9(1));
end
end

Sign in to comment.

Categories

Tags

Asked:

on 9 Apr 2018

Commented:

on 9 Apr 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!