How can I solve a set of equations for multiple inputs?
Show older comments
I have to solve a set of equations for multiple different trials, with 2 variables in each equation. I was told to use a for loop using matrices, but do not know how to execute a for loop using multiple matrices to solve multiple equations. The code I have is posted, but it's basically just the given data. Any help? Thanks!
for
Smax = [1000 1000 1500 1500 200 2500 0.000001 2500];
Smin = [0.000001 -1000 500 -500 -1000 -1200 -4500 1500];
SDelta = Smax - Smin; % Stress Range
Sa = (Smax - Smin)/2; % Alternating Stress
Sm = (Smax + Smin)/2; % Mean Stres
R = Smin / Smax; % Stress Ratio
A = Sa / Sm; % Amplitude Ratio
end;
1 Comment
James Tursa
on 22 Sep 2020
Please post your code as text and highlight it with the CODE button. We can't copy & run pictures.
Answers (1)
Alan Stevens
on 23 Sep 2020
Edited: Alan Stevens
on 23 Sep 2020
You don't need a for loop if all you are doing is calculating SDelta, Sa, Sm, R and A. Just use
Smax = [1000 1000 1500 1500 200 2500 0.000001 2500];
Smin = [0.000001 -1000 500 -500 -1000 -1200 -4500 1500];
SDelta = Smax - Smin; % Stress Range
Sa = (Smax - Smin)/2; % Alternating Stress
Sm = (Smax + Smin)/2; % Mean Stres
R = Smin ./ Smax; % Stress Ratio
A = Sa ./ Sm; % Amplitude Ratio
Notice that in R and A your "/" is replaced by "./" (dot divide). This performs element by element division.
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!