How can I get this function to stop graphing a thousand straight lines and instead graph the data points it's supposed to?
1 view (last 30 days)
Show older comments
When I call the following function, it should give me two nice bell curves. However, it's giving me a thousand straight lines on a single graph. How do I fix it so that I get the data points?
Here is the section of code:
function xprime = dcoupledeta(t,x)
c1 = 1;
c2 = 1;
E = .001;
m = 5;
k = 1;
s=size(t);
eta1 = zeros(1000,1);
eta2 = zeros(1000,1);
P = zeros(1,1000);
P2 = zeros(1,1000);
for j=1:s
for i=1:s
eta1(i) = .0001*i;
eta2(i) = .001*i;
xprime(1)= x(3);
xprime(2)= x(4);
xprime(3)= -eta1(i)*(((x(3)^2)/2) + (c1/(2*m))*x(1)^2 -(E/m))*x(3) - (c1/m)*x(1) + k*(x(2)-x(1));
xprime(4)= -(eta2(i)/m)*x(4) - (c2/m)*x(2) + k*(x(1)-x(2));
xprime = xprime(:);
end
P(j) = (1/100)*eta1(i)*x(4,j)^2;
P2(j) = (1/100)*eta2(i)*x(4,j)^2;
end
figure(j);
hold on;
plot(eta1,P,eta2,P2);
xlabel('\eta')
ylabel('Power')
title('Power vs. \eta')
end
Answers (1)
Chad Greene
on 9 Dec 2014
What are your x and t values?
2 Comments
Chad Greene
on 9 Dec 2014
We need some numbers to work with, and the ode45 line throws an error without tspan. From your question, I have some suspicions about what the problem might be, but I need to be able to replicate the problem to be sure. What values of x and t are you putting into dcoupledeta(t,x)?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!