i get error can any one help
Show older comments
erro in my code pleas help me
my code:
f= @(x,y,z) [((x-4)^2 - z) ;( 2*y-4*z); z+16*(x-8)+1/y -21]
jacobian_matrix = @(x,y,z) [2*(x-10), 0 ,-1;0,2,-4;16,(-1/y^2),1]
x=x0(1,1)
y=x0(2,1)
z=x0(3,1)
itar=0
x1=zeros(3)
while ((det(jacobian_matrix(x,y,z))~=0 && norm(f(x,y,z))>epsilon))
itar=itar+1
hfresh=((jacobian_matrix(x,y,z))\(-1*(f(x,y,z))))
x1=x0+hfresh
x=x1(1,1)
y=x1(2,1)
z=x1(3,1)
x0=x1
end
my input
newton_method([3;4;1],10^-6)
Error using vertcat
Dimensions of arrays being
concatenated are not consistent.
Error in
newton_method>@(x,y,z)[((x-4)^2-z);(2*y-4*z);z+16*(x-8)+1/y,-21]
(line 2)
f= @(x,y,z) [((x-4)^2 - z) ;(
2*y-4*z); z+16*(x-8)+1/y -21]
2 Comments
Walter Roberson
on 10 May 2021
How does
newton_method([3;4;1],10^-6)
map into a call to f (which expects three separate parameters) ?
mohammad massarwe
on 10 May 2021
Answers (1)
Walter Roberson
on 10 May 2021
f= @(x,y,z) [((x-4)^2 - z) ;( 2*y-4*z); z+16*(x-8)+1/y -21]
Inside [] if you have an expression of the form A -B then that does not mean to subtract B from A. Instead it is treated as [A, -1*B] .
Spacing is important. [A-B] and [A- B] and [A - B] are all subtraction, but [A -B] treats the - as unary minus. Consider the expression
[0 -1 1 2]
then it becomes obvious in context that you want a list of four elements, equivalent to [0, -1, 1, 2]; and if you had [0 -1 1] it would still be obvious you were creating a list with negative values... and the same parsing rule holds for [0 -1] which does not suddenly become interpreted as a subtraction 0 minus 1.
Categories
Find more on Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!