Matlab Plot can't work.
Afficher commentaires plus anciens
Hi Guys,
Below is my code, and I have a quesion, when I modify the plot function from plot(x,z,'-*r') to plot(x,z), the figure can't show, Does anyone know why?
clc
clear
clc
f = @(x,y,z) 1/y*(y+z); %where k = 1 for y''
g = @(x,y,z) z ; %for y'
h = 0.1;
x= 0;
z= 1;
y= 1;
%value of y at x = %0.2f and z = 0.2%f is %f\n
for i = 1:25
k1 = h.*f(x,y,z);
j1 = h.*g(x,y,z);
k2 = h.*f(x+h/2,y+k1/2,z+j1/2);
j2 = h.*g(x+h/2,y+k1/2,z+j1/2);
k3 = h.*f(x+h/2,y+k2/2,z+j2/2);
j3 = h.*g(x+h/2,y+k2/2,z+j2/2);
k4 = h.*f(x+h,y+k3,z+j3);
j4 = h.*g(x+h,y+k3,z+j3);
k = (k1+2*k2+2*k3+k4)./6;
j = (j1+2*j2+2*j3+j4)./6;
x = x + h;
z = z + j;
y = y + k;
fprintf('i = %8.0f, y = %8.6f, x = %8.2f, z = %8.6f\n',i,y,x,z);
plot(x,z,'-*r')
hold on
plot(x,y,'-ob')
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
