Value for each loop

조회 수: 16 (최근 30일)
SUSHANT CHAVAN
SUSHANT CHAVAN 2019년 8월 30일
댓글: Star Strider 2019년 9월 1일
v0=0.01;
y=[0.094 0.15]
for c0=[1 2 5 6]
for c1=[5 6 8 7]
[y,v] = ode45(@(y,v)(([c0]/v^2)-([c1]/v)),y ,v0);
disp(v);
end
end
%%How would I get value of 'v' for each combination of c0 and c1. As there is 16 different combinations of c0 and c1 is possible.
%%How to get value for each combination

채택된 답변

Star Strider
Star Strider 2019년 8월 30일
Your only option is likely to iterate over the vectors in nested loops:
v0=0.01;
y =[0.094 0.15];
yv = linspace(min(y), max(y), 25);
c0=[1 2 5 6];
c1=[5 6 8 7];
for k1 = 1:numel(c0)
for k2 = 1:numel(c1)
[y,v(k1, k2, :)] = ode45(@(y,v)((c0(k1)/v^2)-(c1(k2)/v)),yv ,v0);
% disp(v);
end
end
Plotting them is going to be something of a challenge. This could be an option:
figure
hold all
for k = 1:size(v,3)
surf(c0, c1, v(:,:,k))
end
hold off
grid on
xlabel('c0')
ylabel('c1')
zlabel('zv')
view(-45, 20)
  댓글 수: 2
SUSHANT CHAVAN
SUSHANT CHAVAN 2019년 9월 1일
Loads of Thanks....
Star Strider
Star Strider 2019년 9월 1일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by