0
votes

I 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!

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);

1
It has 1000 from the linspace, it loops through all as that will change my p9 value. Does that help clarify? - Alexis Moreno
I’m not sure I understand you. I’ve reresd your comment several times @tehhowch - Alexis Moreno
The warning tell you that it is not possible to isolate x in your equation, you could perhaps use an iterative methode to found the x value (like the fixed point method). So instead of using an analytical methode, try to use a numerical method. But did your error come from this exact code ? Because in this case the equation is explicit ! - obchardon
It looks like you don't even need to code your own numerical method, matlab contains the function vpasolve, so it should work now. - obchardon

1 Answers

1
votes

You certainly have an equation, where x can't be isolated.

For example it is impossible to isolate x in tan(x) + x == 1. So if you try to solve this equation analyticaly, matlab will tell you that x can't be isolated and therefore there is no explicit analytical solution.

So instead of using an analytical method to solve your equation, you need to use a numerical method, it's less "sexy" but this time you will be able to solve your equation.

Life is well done, matlab already integrate a numerical solver: vpasolve.

So your code will look like:

for n=1:number
    %% find p9
    syms x
    eqn = x + 5 == A_t/A_e(n); 
    solx = vpasolve(eqn,x);
    P_9(n) = double(solx);
end