Hello everybody I am trying to make a program that simulates a ray going through a 2d matrix on a set angle, and then highlight the path. When I get to the syms part, I get the "Unable to find explicit solution" error many times. What am I doing wrong there? Thanks in advance!!
clcclear allclose alla=randi([0,64],[6,6]); %create a 6*6 matrix with random values
first_row=1; %set entry point coords
entrypoint=3; %set entry point coordsa(first_row,entrypoint)=0; %pinpoint the entry point in the matrix
angle=45; %set an angle
y(1)=entrypoint; %we're gonna need these in the loop
x(1)=first_row; %we're gonna need these in the loopfor i=2:1:length(a) %repeat till it reaches the end of the matrix
syms x(i) y(i) %define the 2 unknown factors
x(i)=(((y(i)-y(i-1))*(sind(90-angle))/sin(angle))+x(i-1)); %based on A/sin(a)=B/sin(b)
y(i)=((x(i)-x(i-1))*tand(angle)+y(i-1));%based on A/sin(a)=B/sin(b)
t=floor(solve(x(i))); %solve for y
z=floor(solve(y(i))); %solve for x
a(t,z)=0; %highlight the "path" on matrix a
end t %check
z %checka %checkimage(a)
Best Answer
You have
so you expect i to be an integer value.
But on the next line you have
which is the same as
so i becomes an unresolved symbolic value and x and y become symbolic functions.
And that means that when you get to
then x becomes a symbolic function with parameter i, involving y evaluated at the unresolved symbol i and i-1, and also involving the previous symbolic function x (that has no definition) evaluated at i-1 .
Then
y becomes a symbolic function with parameter i, involving the just-defined symbolic function x(i) evaluated at a couple of inputs, and involving the previous symbolic function y (that has no definition) evaluated at i-1 .
This is a mess, and it is not clear what your intentions are.
Perhaps the following will be meaningful to you:
Chances are that it won't be what you want...