Help with quadriatic formula?
이전 댓글 표시
Hi everyone,
We are to create a function using the editor to solve a quadratic formula. The hard part is the user is to be able to input just the equation ie: Ax^2+Bx+C=0 (not the values of ABC). (Below is what I have so far)
____***_*%The user input the formula they want solved_____
function [xpos, xneg] = Roots(equation)
%Quadratic equation format is = Ax^2 + Bx + C = 0
A = strtok(equation, 'x');
B =
C =
%This is the discriminant
D = B .^2 - 4 .* A .* C;
%These are the equation to find the positive and negative values of x
xpos = (-B + sqrt(D)) ./ (2 .* A)
xneg = (-B - sqrt(D)) ./ (2 .* A)
end
댓글 수: 3
Matt Kindig
2013년 9월 12일
To clarify, your input is something like this following, correct?
equation = '3x^2 + 5x + 12=0'
Daniel Shub
2013년 9월 17일
There are lots of parsers for quadratic equations based on regular expressions. This might be easier than using strtok
dpb
2013년 9월 17일
Oh, indeed! The OPs instructor is, however, apparently not amenable to alternate solutions than those suggested based on his comments later on.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Historical Contests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!