Finding the functionality for the loop
조회 수: 3 (최근 30일)
이전 댓글 표시
I am new to Matlab. I am making a formula/syntax book as a part of my club activity. I was finding logics for implementing loops in matlab without actually using loops. Is there any other way?
Is there any other way of writing by not using for loop in matlab
t = linspace(10, 1000, 100);
for 1:n
y(n)=1+t(n)^2;
eq = @(x) (N + x)/(y(n) + k) + N*x*exp(-(t(n)));
end
%Say we need to find the range of values of solution of eq for all values of range
%n. N, k are constants.
%Is it possible to implement the same without for loop
댓글 수: 2
Walter Roberson
2022년 3월 14일
Note that you are overwriting all of eq in each iteration of the loop.
When you say "solution of eq" are you looking for the values of x such that eq(x) == 0 ?
채택된 답변
Walter Roberson
2022년 3월 14일
syms t N k x
T = linspace(10, 1000, 100).';
y = 1 + t^2;
eqn = (N + x)/(y + k) + N*x*exp(-(t))
sol_x = solve(eqn, x)
sols_x = subs(sol_x, t, T);
sols_x(1:5)
sols_x(end)
vpa(limit(sols_x(end), N, 1))
vpa(limit(sols_x(end), N, inf))
댓글 수: 2
Walter Roberson
2022년 3월 14일
Note that if you are not using the symbolic toolbox, then the exp(1000) that shows up in the last entry, will almost certainly overflow double precision to give you infinity at that point.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!