简体   繁体   English

在Matlab中求解非线性方程

[英]solving nonlinear equations in matlab

I have a homework question that I cannot answer. 我有一个无法回答的作业问题。 Here is the question prompt: 这是问题提示:

  1. Define Eq. 定义方程 8.3 and Eq. 8.3和等式 8.4 in a function. 8.4中的一个功能。 This function should take a vector of joint angles ( 此函数应采用关节角的向量( \\α and \\ beta ) as input and should return a column vector containing the two functions ( )作为输入,并应返回包含两个函数的列向量( f_ {1} and f_ {2} ) evaluated at those angles. )以这些角度进行评估。 The function should contain the link lengths and values of 该函数应包含链接长度和值 R {des} and H_ {des} = 1.1 for calculation. 用于计算。 Include your code in your solution. 在解决方案中包含您的代码。

Equations 8.3 and 8.4 are: 公式8.3和8.4为:

式 (8.3) (8.3)

式 (8.4) (8.4)

where 哪里

d_ {1} = d_ {2} = 1.0

R {des} = 1

H_ {des} = 1.1

\\ alpha = \\ left \\ langle 0,\\ frac {\\ pi} {2} \\ right \\ rangle

\\ beta = \\左\\ langle 0,\\ pi \\右\\ rangle

Here is the function I wrote: 这是我写的函数:

function F = rob_arm (alphag, betag)
F = (1).*cos(alphag)+ (1).*(cos(alphag+betag))-(1) ;
  (1).*sin(alphag) + (1).*(sin(alphag+betag))-(1.1) ;
end

Because alpha and beta are matrices of different sizes, I used meshgrid to create alphag and betag , and used those matrices to calculate the values of rob_arm . 由于alphabeta是大小不同的矩阵,因此我使用meshgrid创建alphagbetag ,并使用这些矩阵计算rob_arm的值。 After four hours of messing with this, I'm not even sure what the question is asking anymore, and the TA's are not currently answering emails. 经过四个小时的讨论,我什至不知道问题在问什么,TA暂时没有回复电子邮件。 I wrote the following code, to try and force rob_arm into a single column: 我编写了以下代码,尝试将rob_arm强制为单个列:

alpha = 0:pi/100:(pi/2); %define angle alpha
beta = 0:pi/100:pi; %define angle beta

[alphag, betag] = meshgrid (alpha, beta); %mesh grid alpha and beta b/c different matrix dimensions
arm_pos = rob_arm (alphag, betag);

for ii = 1:1:101
    for k = 1:1:51
 col_vec (1,1:1:5151) = arm_pos(ii,k);
    end
end

Ignoring the query to create a column vector, the resulting output, arm_pos is good output. 忽略创建列向量的查询,结果输出arm_pos是好的输出。 I can graph it and I get a very pretty picture of all the possible points that this robot arm can 'reach.' 我可以将其绘制图形,并且可以很清楚地看到该机械臂可以“到达”的所有可能点。

But because I am dumb and have been trying this for many hours, it's not saving successive values of rob_arm into col_vec , it just replaces it each time and I end up with a 1x1 matrix. 但是由于我很笨,并且已经尝试了许多小时,所以没有将rob_arm连续值rob_armcol_vec ,它每次都替换一次,结果得到一个1x1矩阵。 Ultimately, the goal will be to use the Newton-Raphson method to determine the zeroes of this function, but that's a long ways off. 最终,目标是使用Newton-Raphson方法确定该函数的零点,但这还有很长的路要走。 I am thinking if I can get all of the values calculated by rob_arm into a single column, then I can answer this question. 我在想如果我可以将rob_arm计算的所有值rob_arm放在一个列中,那么我可以回答这个问题。

The next question is: 下一个问题是:

  1. Create a separate function that accepts input of a single row vector containing the pair of angles 创建一个单独的函数,接受包含一对角度的单个行向量的输入 \\α and \\ beta . The output of the function should be the Jacobian (a 2 by 2 matrix). 函数的输出应为雅可比行列式(2 x 2矩阵)。 First, calculate the derivatives of Eqs. 首先,计算方程式的导数。 8.3 – 8.4 by hand, then put them into your function. 手动操作8.3 – 8.4,然后将其放入您的功能中。 Include your function code in your solution 在解决方案中包含功能代码

Which I will need to ask for clarification on, because I don't understand how a 1 x 51 matrix ( alpha ) and a 1 x 102 matrix ( beta ) could be accepted into a single row vector, that would then output a 2x2 matrix. 我需要澄清一下,因为我不明白如何将1 x 51矩阵( alpha )和1 x 102矩阵( beta )接受到单个行向量中,然后输出2x2矩阵。 I know what the Jacobian is, and it is the partial derivitives of my two functions, not a matrix of values. 我知道什么是雅可比行列式,它是我的两个函数的偏导数,而不是值矩阵。

If anyone wants to give me a hand, that would be super awesome. 如果有人想帮我,那真是太棒了。

You function definition is not right, you should use something like 您的函数定义不正确,您应该使用类似

function F = rob_arm (alphag, betag) 
 F = [(1).*cos(alphag)+ (1).*(cos(alphag+betag))-(1) ; ...   
      (1).*sin(alphag) + (1).*(sin(alphag+betag))-(1.1)]; 
end

Without the three dots " ... " MATLAB performs this calculation 没有三个点“ ...”,MATLAB将执行此计算

 (1).*sin(alphag) + (1).*(sin(alphag+betag))-(1.1);

but does nothing with the result, and returns 但是对结果不执行任何操作,然后返回

  F = (1).*cos(alphag)+ (1).*(cos(alphag+betag))-(1) ; 

which is not what you want, half the F values are missing. 这不是您想要的,缺少一半的F值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM