How to do a loop to evaluate a function with a varying value?
Show older comments
Hi there! Studying crack propagation in Comsol, I got to a result that is a function that consists of 4 parameters: Chi, Omega, Lambda0 and CS. The equation is:
J = (Cs.*Omega.*lambda0.^8-Cs.*Omega.*lambda0.^5-2.*chi.*lambda0.^3+lambda0.^3+2.*chi).^2/(2.*chi.*lambda0.^3-lambda0.^3-2.*chi).^2;
How do I evaluate the influence of each parameter on the final value? To me, I could fix 3 parameters and vary the remaining one (the simplest case). But, Is there any how to make this analisys in a different way?
I tried a loop for the simplest case, but it doesn't work:
for i=1:100
chi=1:01:1;
Omega=4;
Cs=2;
lambda0=5;
x(i)=(Cs.*Omega.*lambda0.^8-Cs.*Omega.*lambda0.^5-2.*chi.*lambda0.^3+lambda0.^3+2.*chi).^2/(2.*chi.*lambda0.^3-lambda0.^3-2.*chi).^2;
end
plot(chi,x)
Shame on me, guys! LOL I am terrible at MATLAB.
Can anyone help me, please?
Answers (1)
Torsten
on 23 Jan 2018
chi=0:0.01:1;
Omega=4;
Cs=2;
lambda0=5;
x=(the expression from above);
plot(chi,x)
Best wishes
Torsten.
3 Comments
InWend
on 23 Jan 2018
Torsten
on 23 Jan 2018
x will be a vector of the same size as chi.
Best wishes
Torsten.
Star Strider
on 23 Jan 2018
You need to define ‘chi’ correctly:
chi=1:01:1;
chi =
1
Categories
Find more on Functional Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!