Plotting a line in MATLAB to calculate real root of equation

1 view (last 30 days)
I wrote the following script to calculate the real root (i.e. where Function is equal to zero):
a = 0.0245; b = 1.66*(10.^(-5)); P = 220*(10.^5); T = 300; R = 8.314;
x = 0:100:9000; Function =((x*R*T)/(1-(b*x))) - ((a*(x.^2))/((1+(2*b*x))-(b.^2)*(x.^2))) - P; plot(x,Function)
But only one value is being plotted, as in the plot is a horizontal straight line. If someone could help me figure this out I would be very grateful.
Thanks!

Answers (1)

the cyclist
the cyclist on 6 Mar 2013
You neglected to use ./ for element-wise division. Try this:
Function =((x*R*T)./(1-(b*x))) - ((a*(x.^2))./((1+(2*b*x))-(b.^2)*(x.^2))) - P;

Community Treasure Hunt

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

Start Hunting!