How to store values in a matrix?

조회 수: 4 (최근 30일)
Valentina Tudor
Valentina Tudor 2022년 9월 23일
댓글: Sharmin Kibria 2022년 9월 23일
Hello. I am trying to store my theta and E values in a matrix to be able to plot them. This is what I have done so far but it does not work. I would appreciate some help. Thank you so much!
clear all
close all
clc
[separated off so if somebdody downloads won't wipe their workspace accidentally -- dpb]
% define degree increments of 5 from 0 to 90
theta = 0:5:90;
%given information
Eone = 1.54*10^11;
Etwo = 8.96*10^9;
Ethree = Etwo;
Vonetwo = 0.32;
Vonethree = Vonetwo;
Vtwothree = 0.5;
Gonetwo = 5.32*10^9;
Gonethree = Gonetwo;
Gtwothree = 2.99*10^9;
% S matrix
S = [(1/Eone) (-Vonetwo/Eone) (-Vonethree/Eone) 0 0 0;
(-Vonetwo/Eone) (-1/Eone) (-Vtwothree/Etwo) 0 0 0 ;
(-Vonethree/Ethree) (-Vtwothree/Ethree) (1/Ethree) 0 0 0;
0 0 0 (1/Gonetwo) 0 0 ; 0 0 0 0 (1/Gonethree) 0;
0 0 0 0 0 (1/Gtwothree)];
syms sigma [3 3]
sigma ;
sigmaprime = [ 1 0 0 ; 0 0 0 ; 0 0 0 ] ;
%define the rotating matrix for theta from 0 to 90 degrees in increments
%of 5
for theta = 0:5:90
R = [cos(theta) (-sin(theta)) 0; sin(theta) cos(theta) 0; 0 0 1];
end
%get sigm prime
Rt= R.';
sigma = Rt * sigmaprime * R;
%sigma as 1 by 6
newsigma = [ 0.2008; 0.4006 ;0; 0.4006; 0.7992; 0];
%get epsilon by sigms times S
epsilon = newsigma .* S;
%epsilon as 3 by 3
newepsilon = [ 0.0013 -0.0004 -0.0004; -0.0008 -0.0026 -0.0224; 0 0 0];
%find epsilon prime
epsilonprime = R * newepsilon * Rt;
%solve for modulus E by epsilon'(1,1)/sigma'(1,1)
E = epsilonprime(1,1)/newsigma(1,1)
%plot
E = zeros(19,1)
theta = zeros(19,1)
plot(theta,E)
xlabel('θ = Degrees')
ylabel('Modulus of the material as a function of θ (Pa)')
title('Exx Modulus')
  댓글 수: 1
Sharmin Kibria
Sharmin Kibria 2022년 9월 23일
You are trying to plot theta and E, right? It seems like you are setting both theta and E to zero on the line just before plot. When you are calling the plot function, it is plotting only the (0,0) value. That is why you don't see the desired plot. Whateevre calculations you have done gets overwritten by the E = zeros(19,1)
theta = zeros(19,1) command.
I hope it helps.

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

답변 (1개)

Walter Roberson
Walter Roberson 2022년 9월 23일
편집: Walter Roberson 2022년 9월 23일
for theta = 0:5:90
R = [cos(theta) (-sin(theta)) 0; sin(theta) cos(theta) 0; 0 0 1];
end
That is not creating one R for each different theta, it is overwriting R each time.
You do matrix multiplication by R or R' so you cannot simply make R into a 3d matrix. You could potentially recode using pagemtimes() calls if you made R into 3d.
Or perhaps you should make theta a symbolic scalar and carry it through until afterwards you subs in a vector of values.
Oh, and be careful, you are taking sin of 5 to 90 radians not degrees.

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by