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)
| I was expecting to see this: | http://www.mathworks.com/matlabcentral/answers/uploaded_files/25540/Capture.JPG
Thank you.
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!