필터 지우기
필터 지우기

Differentiation of two variables in a polynomial equation

조회 수: 4 (최근 30일)
bayoishola20
bayoishola20 2015년 2월 17일
댓글: John D'Errico 2015년 2월 17일
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