From: Ravi on
How do i plot a surface plot for the following function:
here w depends on two input variables err_theta and err_X

Assume that err_theta varied from -1.57 to 1.57 and err_X
varies from -5 to 5

code starts from here:
************************************************************
x=-1.57:0.157:1.57;
y=-5:0.5:5;
[X,Y]=meshgrid(x,y);
Z=fcnw_3(X,Y);
surf(X,Y,Z),shading interp;
axis([-1.57 1.57 -5 5 -0.5 0.5]);
xlabel('Orientation Error radians');
ylabel('Position Error mts');
zlabel('angular Velocity rad/sec');
************************************************************
%functin for fcn_3
function z = fcn_3(x,y)


w='fcn4(x,y)';

z=eval(vectorize(w));
end
*************************************************************
%function for fcn4
function w = fcn4(err_theta,err_X)

w=0;
wmax=0.5;err_theta_max =1.57;
err_X_max=5.0;
k1=(1-(err_X/err_X_max));k3=(1-(err_theta/err_theta_max));
k2=(1+(err_X/err_X_max));k4=(1+(err_theta/err_theta_max));


if(err_X>0)

if(err_theta>0)

w=(-(err_theta/err_theta_max)-(err_X/err_X_max))*wmax/2;


end

if(err_theta<=0)

w=(-(err_theta/err_theta_max)*k1-(err_X/err_X_max)*k4)*wmax;


end
end
if (err_X<=0)

if(err_theta>=0)

w=(-(err_theta/err_theta_max)*k2-(err_X/err_X_max)*k3)*wmax;

end

if(err_theta<0)
w=(-(err_theta/err_theta_max)-(err_X/err_X_max))*wmax/2;

end
end
end
************************************************************


I tried using surf command...but i m not able to get it
gives me an error Z must be a matrix.
Please can any one help me about this

Thanks in Advance

BR
Ravi
From: Bob on
Ravi, the problem may be confusion about matrices and scalars. Have
you stepped through the code with the debugger? That's probably the
best way to figure out what went wrong, where and fix it.

Cheers
Bob
From: Ravi on
Bob <rbemis(a)mathworks.com> wrote in message
<7b3827f1-b601-4bf9-b76d-86d49b77fde6(a)b64g2000hsa.googlegroups.com>...
> Ravi, the problem may be confusion about matrices and
scalars. Have
> you stepped through the code with the debugger? That's
probably the
> best way to figure out what went wrong, where and fix it.
>
> Cheers
> Bob
Hi Bob,
I tried with in debugger mode.As soon as I enter the if
condition it gives me the error .

The problem is in evaluation of the if condiition

in this case in the function fcn4

if(err_X>0).
As soon as i enter this it gives me the error "Z must be
matrix not a scalar or vector"

How do I overcome this error


cheers
Ravi
 | 
Pages: 1
Prev: fix digit in number
Next: OS compatibility