How can I save only the values that work?

1 view (last 30 days)
N8TM8T
N8TM8T on 2 Dec 2020
Answered: VBBV on 2 Dec 2020
I am trying to numerically solve 1 equation for 2 unknowns. I want to find the minimum value of m2 (and it's associated k2 value) that results in X to be less than 0.01. I think I have a for-loop that works, but I have been unable to figure out a way that I can extract the appropriate values of m2 and k2. (The reason I only am looping m2 and not also k2 is because I can always solve for k2 once I have a known working value for m2)
Here is my work so far:
clc; close all; clear;
k1 = 9.6*10^4;
m1 = 53.9305;
F0 = 460;
wstep = 0.0001;
m2 = [0.1:0.1:1000];
%preallocate
X = nan(1,100000);
for i = 1:length(m2)
X =@(w,k2) abs(((k2-m2(i).*w.^2).*F0)./((k1+k2-m1.*w.^2).*(k2-m2(i).*w.^2)-k2.^2));
w = [40+wstep:wstep:50];
k2 = [1:1:100000];
Xsave = X(w,k2);
end

Accepted Answer

VBBV
VBBV on 2 Dec 2020
w = [40+wstep:wstep:50];
k2 = [1:1:100000];
for i = 1:length(m2)
X =@(w,k2) abs(((k2-m2(i).*w.^2).*F0)./((k1+k2-m1.*w.^2).*(k2-m2(i).*w.^2)-k2.^2));
Xsave(i,:) = X(w,k2);
end

More Answers (0)

Categories

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

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!