??? Undefined function or method 'power' for input arguments of type 'function_handle'.

조회 수: 8 (최근 30일)
suj gal
suj gal 2015년 2월 25일
편집: Mischa Kim 2015년 2월 25일
hello guys, I am quite new to matlab and am trying to do a newton-raphson iteration. but i keep getting this error: ??? Undefined function or method 'power' for input arguments of type 'function_handle'.
Error in ==> @(z)(z.^3-z.^2+m*z+m2)
Error in ==> graded_lab1 at 24 x1=y-(z1(z)/dz(z));
Some of the code i temporarily commented out. but i am also having trouble doing a for loop inside a for loop. Here's the code:
%problem2
tc=373.56;
pc=88.9;
t=293;
p= [1 1.5 2 2.5 3 5 10 15 25 50];
r=8.3144621;
a=(r*r*(sqrt(tc*tc*tc*tc*tc)))/(9*pc*(sqrt(8)-1));
b=((sqrt(8)-1)*r*tc)/(3*pc);
A=(a*p)/(r*r*sqrt(t*t*t*t*t));
B=(b*p)/(r*t);
%for i=1:10
m=(A(i)-B(i)-B(i)*B(i))
m2=-A(i)*B(i)
z1 = @(z) (z.^3-z.^2+m*z+m2);
dz = @(z) 3*z.^2-2*z+m;
y=0;
for u=1:1:100
x1=y-(z1(z)/dz(z));
y=x1
if x1==y break
end
end
%v(i)=(root(1)*r*t)/p(i);
%end
%v(3)=(Zed*r*t)/p
v
plot(v);

답변 (1개)

Mischa Kim
Mischa Kim 2015년 2월 25일
Suj, two things: root and Zed are not defined. In
x1 = y - (z1(z)/dz(z));
the running index is probably u, and not z, I assume.
  댓글 수: 2
suj gal
suj gal 2015년 2월 25일
u is just for iterations from 1 to 100 no? i thought z1(z) would be referring to the function z?
Mischa Kim
Mischa Kim 2015년 2월 25일
편집: Mischa Kim 2015년 2월 25일
OK. That's what you meant. I have started cleaning up your code. It's not quite done yet... but running.
...
B = (b*p)/(r*t);
del = 1e-5;
max_i = 10;
v = zeros(1,max_i); % pre-allocate memory
for ii = 1:max_i
m = (A(ii)-B(ii)-B(ii)*B(ii));
m2 = -A(ii)*B(ii);
z1 = @(z) (z.^3-z.^2+m*z+m2);
dz = @(z) 3*z.^2-2*z+m;
y = 0;
for u = 1:1:100
deltaz = (z1(y)/dz(y)); % the arg seems to be y
x1 = y - deltaz;
if (abs(deltaz)< del) % close enough to solution?
v(ii) = x1; % save solutions
break
end
y = x1;
end
end
plot(v);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by