Filter löschen
Filter löschen

Differentiation of two variables in a polynomial equation

4 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

John D'Errico
John D'Errico am 17 Feb. 2015
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 Kommentare
bayoishola20
bayoishola20 am 17 Feb. 2015
Bearbeitet: bayoishola20 am 17 Feb. 2015
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 am 17 Feb. 2015
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]

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by