[英]Trying to solve a quadratic equation in Matlab
I have just started to use Matlab and I am struggling to solve quadratic equations. 我刚刚开始使用Matlab,正在努力解决二次方程式。 I am studying with the following guide:
我正在学习以下指南:
A guide to Matlab for beginners and experienced users
适用于初学者和有经验的用户的Matlab指南
I tried to solve the equation provided by the book (page 17). 我试图解决本书提供的方程式(第17页)。 Despite typing exactly what the book instructed, I did not get the desired output.
尽管键入的内容与本书的指示完全相同,但我没有获得所需的输出。 Note that firstly I tried with solve command and secondly with fzero but none worked out:
请注意,首先我尝试使用solve命令,其次使用fzero,但没有解决:
>> clear
>> syms x
>> solve ('x^2 - 2*x - 4 = 0')
Error using solve>getEqns (line 418)
List of equations must not be empty.
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
>> fzero ('x^2 - 2*x - 4 = 0')
Error using fzero (line 121)
FZERO requires at least two input arguments or a structure
with valid fields.
I do not understand the correction 'List of equations must not be empty' after using solve command. 使用solve命令后,我不理解“方程列表不能为空”的更正。 Besides, when I tried to use fzero command I got 'FZERO requires at least two input arguments or a structure with valid fields' which I did not get the hang of either.
此外,当我尝试使用fzero命令时,我得到了“ FZERO至少需要两个输入参数或具有有效字段的结构”,但我都没有这样做。 I looked for an alternative and I found x could be enclosed in parenthesis:
我寻找了替代方法,发现x可以放在括号中:
>> solve ('x^2 - 2*x - 4 = 0', x)
Error using solve>getEqns (line 418)
List of equations must not be empty.
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
But again 'List of equations must not be empty' came as a result. 但是结果又出现了“方程列表一定不能为空”。 Please take into consideration the fact that I am a beginner and I understand this question may be too obvious to you, however I have been trying for a while and could not figure it out.
请考虑以下事实:我是一个初学者,并且我知道这个问题对您来说可能太明显了,但是我已经尝试了一段时间,无法解决。
Thanks 谢谢
Based on the following link, it looks like specifying your equation as a string (char vector) might be your issue. 根据以下链接,看起来将方程式指定为字符串(字符向量)可能是您遇到的问题。 Equations and systems solver in MATLAB .
MATLAB中的方程和系统求解器 。 In your situation, I would try the following:
在您的情况下,我将尝试以下操作:
clear
syms x
solve(x^2 - 2*x - 4 == 0, x);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.