How to solve an equation with two variables but one variable is an array?

Hi, I'm still relatively new to coding, and I have a question about solving a quadratic equation, then using the results to graph using semilogx. I have a quadratic equation with two variables, one of which I'm solving for and the other an array of values. More specifically, I'm solving for L and one of the coefficients is 1/(1+x) but x goes from 0 to 10^10 and I need to find the roots for every value of x on intervals of 100. I then need to plug the answer from the equation into another equation, and graph x vs that answer. I tried syms and roots, but I keep getting errors. Any tips? Thank you!

2 Comments

If you provide all the equations, I will likely be able to help you.
Thank you so much! So it's an acid-base setup. x goes from 0 to 10^10. pKa= -log(0.000138).
L^2+L(10^-pKa)-((10^-pKa)(1/(1+x)))=0, and I need to solve for L. Then pH = -log(L). I need to use semilogx to graph x versus pH.

Sign in to comment.

 Accepted Answer

I assume log10 is what you want. If not you can easily change it. You might have memory problems for 1e10.
x=0:1e8;
pKa=0.000138;%10^log10(0.000138) easier
L=(-pKa+sqrt(pka^2+4*pKa./(1+x)))/2;%some simple algebra helps
pH=-log10(L);
semilogx(x,L);

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!