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

11 views (last 30 days)
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');

Answers (1)

Walter Roberson
Walter Roberson on 15 Jun 2015
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 Comments
Walter Roberson
Walter Roberson on 15 Jun 2015
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

Sign in to comment.

Categories

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

Community Treasure Hunt

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

Start Hunting!