Using For loop to plot graphs of functions

2 views (last 30 days)
HUST Student
HUST Student on 10 Jun 2018
Commented: Stephen23 on 10 Jun 2018
I'm trying to write a matlab (for loop) code to produce the graphs: Q as a function of A, F as a function of A, Z as a function of A from the known functions f1, f2 and f3 Z = f1 (A, F, Q) F = f2 (A, Q, Z) A = f3 (Z, Q). I made several attempts that were unsuccessful:
clear
syms w e d n A Z F Q;
w=pi;
e=0.5;
d=10;
n=1;
eqn1 = Z+A.*w./(1-Q.*(1+e))*cos(F)==0;
eqn2 = cos(F+2.*Q.*n.*pi)+Z.*((e-Q.*(1+e))./A.*w)==0;
eqn3 = A-1/(2.*w.*abs(sin(Q.*n.*pi))).*(((1-e).*Z).^2+(d.*w+2.*(1+e).*(1-Q).*Q.*n.*pi.*Z).^2).^0.5==0;
equations = [eqn1 eqn2 eqn3];
vars = [A Z F Q];
range = [0 10;-40 40;0 6;NaN NaN];
for A=0:0.5:10;
for i=1:5
temp=vpasolve(equations, vars, range, 'random', true);
sol(i,1)=temp.Z;
sol(i,2)=temp.F;
sol(i,3)=temp.Q;
end
figure (1);
subplot(2,2,1)
plot(A,sol(i,1));
xlabel('A');
ylabel('Z');
subplot(2,2,2)
plot(A,sol(i,2));
xlabel('A');
ylabel('F');
subplot(2,2,3)
plot(A,sol(i,2));
xlabel('A');
ylabel('Q');
end
Error using getEqnsVars (line 50) Expecting two arguments: a vector of equations and a vector of variables.
Error in sym/vpasolve (line 95) [eqns,vars] = getEqnsVars(varargin{1:N});
Error in Sucesso (line 15) temp=vpasolve(equations, vars, range, 'random', true);
I do not know how to solve this error, because in the three equations eqn1 eqn2 eqn3 A is a variable that in the loop assumes the constant values in the interval (0, 10) so in each loop step a system of three equations with three variables (Z, Q, F) supposed to be solved.
If someone can help me I would thank you a lot.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!