Matrix with angles that change with each iteration. For loop?

2 次查看(过去 30 天)
I trying to create a plot using a matrix that changes angles from 0 to 180. I have two issues that I can't figure out. 1 How can I make it so my T value changes every time with each angle, and 2.How do I extract specific values from the resultant matrix sigma? I only want all the values in the first row first column and the first row second column in separate values so I can plot them? Maybe I'm approaching this while thing wrong, below is the code I came up with. Any help is highly appreciated.
c
lc; close all; clear all;
sig = [45 30; 30 -60]
for i = 0:180
T = [cosd(i) sind(i);-sind(i) cosd(i)]
sigma=T*sig*(T)'
primesig = sigma(1,1)
primetau = sigma(1,2)
end
plot(primesig,primetau)
xlabel('sigma');
ylabel('tau');
title('Stress VS Strain');

回答(1 个)

Walter Roberson
Walter Roberson 2015-6-15
Your code already uses a different T for each iteration and already extracts sigma values as needed. Your code has a different problem: it overwrites the prime* variables on each iteration. Instead of your code
primesig = sigma(1,1)
primetau = sigma(1,2)
you should have
primesig(i) = sigma(1,1)
primetau(i) = sigma(1,2)
  3 个评论
Walter Roberson
Walter Roberson 2015-6-15
More generally when you have a list of values that you want to go through, then a useful technique is to assign the list to a variable and step through the variable:
ivals = 0:180; %put values in variable
for K = 1 : length(ivals) %iterate over indices of variable
i = ivals(K); %retrieve the value for this iteration
T = [cosd(i) sind(i);-sind(i) cosd(i)];
sigma=T*sig*(T)';
primesig(K) = sigma(1,1); %store relative to loop count
primetau(K) = sigma(1,2); %store relative to loop count
end

请先登录,再进行评论。

类别

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