How to do a loop to evaluate a function with a varying value?
显示 更早的评论
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?
回答(1 个)
Torsten
2018-1-23
chi=0:0.01:1;
Omega=4;
Cs=2;
lambda0=5;
x=(the expression from above);
plot(chi,x)
Best wishes
Torsten.
3 个评论
InWend
2018-1-23
Torsten
2018-1-23
x will be a vector of the same size as chi.
Best wishes
Torsten.
Star Strider
2018-1-23
You need to define ‘chi’ correctly:
chi=1:01:1;
chi =
1
类别
在 帮助中心 和 File Exchange 中查找有关 Functional Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!