solve equation and return a column vector array which has lower root instead of lower and upper root

1 view (last 30 days)
Hi guys,
I have an equation which I want to solve for but i'm trying to make it return a column vector of solutions. Say if the input y is a column vector array i.e. [100,200,300,400,500,600,700] I want the solve function to return a column vector as well. The problem lies with equation which solves for two roots and I was hoping to get the lower root i.e.
sol=solve(eqn==0,y);
sol(1);
However it ruins the 'size' of the matrix and i was wondering if anyone knows how to selectively obtain all the lower roots i.e. sol(1) if the solution has 2 solutions.
Any hints would be appreciated.

Accepted Answer

Star Strider
Star Strider on 28 Jun 2015
You don’t give enough information to provide a specific solution.
If you are solving for the zeros of a one-variable function, it might be most appropriate to use matlabFunction to create an anonymous function out of ‘eqn’, and then use fzero, fsolve, or a related function to find the roots. Depending on what it returns, you can choose the root you want to keep.
Use a loop to define each element of your [1:7]*100 vector in ‘eqn’, and solve it in each iteration.
  2 Comments
sarah
sarah on 28 Jun 2015
Thanks. I'll try that and show the specific solution if i get stuck.
Sorry for that i'll keep that in mind next time i ask a question.
Star Strider
Star Strider on 28 Jun 2015
My pleasure.
No worries — it just makes it easier to provide a specific Answer.
If you get stuck, please post the relevant parts of the code you wrote. If it threw any errors, post the complete red text of any errors it threw. If it ran but didn’t do what you wanted, describe what it did you didn’t want it to, and what it didn’t do that you wanted it to.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!