Search code examples
matlabplotsolversymbolic-math

Matlab Plotting the Result of Solving An Equation


I am trying to solve an equation, and then plot the result. Here is my script:

>> syms h t 
>> eq = 100*((100+(10-h)^2)/(10-h)) - t - 2000

eq =

- t - (100*((h - 10)^2 + 100))/(h - 10) - 2000

>> solve(eq,h);
>> solve(eq,h)

ans =

   ((t*(t + 4000))/10000)^(1/2)/2 - t/200
 - t/200 - ((t*(t + 4000))/10000)^(1/2)/2

ezplot(((t*(t+4000))/10000)^(1/2)/2-t/200-t/200-((t*(t+4000))/10000)^(1/2)/2)

Rather than plot the function

((t*(t+4000))/10000)^(1/2)/2-t/200-t/200-((t*(t+4000))/10000)^(1/2)/2 

it plots the function -t/100. Why did it do this? How can I amend this?


Solution

  • That's not one function wrapped onto two lines. The solve function returned two separate solutions to your equation. eq is quadratic in h, so you might expect there to be two solutions. You can plot each of the solutions like this:

    s = solve(eq,h);
    figure
    ezplot(s(1))
    figure
    ezplot(s(2))