V150
V150

Reputation: 13

(GNU Octave/MATLAB)'x' is specified as variables of equations, but keep saying x is not specified

'x' is specified as @(x), but error message keeps coming up.

    <i> function F = drawCFRPgraph0726(X, y, E, I, A, G, r, c, m)
    t(1) = pi/2+0.0000001;
    i = 1;
     while t(i)<pi
     disp(t(i));
     for k = 1:500
     L(k) = 0.000001*k;
     dvdx(x) = @(x) ((x/3-L(k)/2)(c*L(k)*m/(c+r)-x(t(i)-y-pi/2))/(x-L(k))+x*       (L(k)/2-x/3)(c*L(k)*m/(c+r)-x(t(i)-y-pi/2))/(x-L(k))^2+x(c*L(k)*m/(c+r)-x(t(i)-y-pi/2))/(3*(x-L(k)))+x*(y-t(i)+pi/2)*(x/3-L(k)/2)/(x-L)+x*t(i)-x*y-pi*x/2)/L(k);
     d2vdx2(x) = @(x) ((-2*x/3+L(k))*(c*L(k)*m/(c+r)-x*(t(i)-y-pi/2))/(x-L(k))^2+x*(2*x/3-L(k))*(c*L(k)*m/(c+r)-x(t(i)-y-pi/2))/(x-L(k))^3-2*x*(c*L(k)*m/(c+r)-x*(t(i)-y-pi/2))/(3(x-L(k))^2)+2*(c*L(k)*m/(c+r)-x*(t(i)-y-pi/2))/(3*(x-L(k)))+(y-t(i)+pi/2)*(2*x/3-L(k))/(x-L(k))+x*(-2*x/3+L(k))*(y-t(i)+pi/2)/(x-L(k))^2+2*x*(y-t(i)+1.5708)/(3*(x-L(k)))+t(i)-y-pi/2)^2/L(k)^2;
     A(k) = quad(dvdx(x), 0, L(k));
     B(k) = quad(dv2dx2(x), 0, L(k));</i>

Upvotes: 1

Views: 46

Answers (1)

Ander Biguri
Ander Biguri

Reputation: 35525

you are wrongly defining the anonymous function.

To define them properly you should:

dvdx = @(x) ((x/3-L(k)/2)(c*L(k)*m/(c+r)-x(t(i)-y-pi/2))/(x-L(k))+x*       (L(k)/2-x/3)(c*L(k)*m/(c+r)-x(t(i)-y-pi/2))/(x-L(k))^2+x(c*L(k)*m/(c+r)-x(t(i)-y-pi/2))/(3*(x-L(k)))+x*(y-t(i)+pi/2)*(x/3-L(k)/2)/(x-L)+x*t(i)-x*y-pi*x/2)/L(k);

This means: now dvdx is a function that takes 1 argument (@(x)) and evaluates it with the following equation ((x/2-L(k) .... But x is not defined outside, the same way X, y, E, I, A, G, r, c, m are not defined outside, just inside the function.

The first input of quad is a function, and the function is not dvdx(x) but just dvdx

Upvotes: 5

Related Questions