Finding the functionality for the loop

1 回表示 (過去 30 日間)
Amy Topaz
Amy Topaz 2022 年 3 月 14 日
コメント済み: Amy Topaz 2022 年 3 月 14 日
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
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 ?
Amy Topaz
Amy Topaz 2022 年 3 月 14 日
yes

サインインしてコメントする。

採用された回答

Walter Roberson
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))
eqn = 
sol_x = solve(eqn, x)
sol_x = 
sols_x = subs(sol_x, t, T);
sols_x(1:5)
ans = 
sols_x(end)
ans = 
vpa(limit(sols_x(end), N, 1))
ans = 
vpa(limit(sols_x(end), N, inf))
ans = 
  2 件のコメント
Walter Roberson
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.
Amy Topaz
Amy Topaz 2022 年 3 月 14 日
Thank you so much for detailed explanation

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by