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

1 次查看(过去 30 天)
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.

采纳的回答

Star Strider
Star Strider 2015-6-28
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 个评论
sarah
sarah 2015-6-28
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 2015-6-28
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by