Differentiation of two variables in a polynomial equation

4 次查看(过去 30 天)
Please the differential part gives giving me empty curly brackets instead of values in this code set.
% Initial x1 and x2
x1 = 5, x2 = 4
% Equations
y1 = (x1-3)^2 + (2*x2 - 8)^2
y2 =(x1-4)^2 + (x2 - 10)^2
%Given y values
y = [5;49]
% First set of y values
yo = [y1;y2]
f = y - yo
A11 = diff(poly((x1-3)^2 + (2*x2 - 8)^2),x1)
A12 =diff(poly((x1-3)^2 + (2*x2 - 8)^2),x2)
A21 =diff(poly((x1-4)^2 + (x2 - 10)^2),x1)
A22 =diff(poly((x1-4)^2 + (x2 - 10)^2),x2)
Thank you.

采纳的回答

John D'Errico
John D'Errico 2015-2-17
x1 and x2 are numbers. You set them as such. Remember this line?
x1 = 5, x2 = 4
you cannot differentiate with respect to a number.
  2 个评论
bayoishola20
bayoishola20 2015-2-17
编辑:bayoishola20 2015-2-17
okay, then what should it be? Because when I do this:
A11 = diff(poly((x1-3)^2 + (2*x2 - 8)^2),x1)
It tells me
Undefined function or variable 'x1'.
John D'Errico
John D'Errico 2015-2-17
I'd start with the statement
syms x1 x2
This tells MATLAB that these are symbolic variables, something that you can differentiate.
When you defined them instead as 5 and 4 respectively, you told MATLAB they were simple numbers, just constants.
Later on, IF you have a specific value to evaluate a derivative at, then you can use subs.
Oh, by the way, When you define the variable A11, this does not create the (1,1) element of the matrix A, just a scalar variable named A11. I think you need to learn about brackets, [], and how to concatenate things into an array. Thus, see what this does:
[1 2;3 4]

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by