how to write in matlab

3 ビュー (過去 30 日間)
msr16
msr16 2019 年 2 月 4 日
コメント済み: Walter Roberson 2023 年 10 月 23 日
hi, i am having c code how to write the below code in matlab
for (i = 0 ; i < n; i++)
scanf("%d", &num[i]);
for (j = 1; j <= n; j++) {
for (i = 0; i < n-1; i++) {
temp = num[i];
num[i] = num[i+1];
num[i+1] = temp;
print(num, n);
}
}

回答 (4 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 2 月 4 日
%Please note I did not check the logic of the code
for i=1:n
check here sscanf
for j=1:n
for i=1:n
temp=num(i);
num(i)=num(i+1);
num(i+1)=temp;
fprintf('%d %d',num,n)
end
end
end
  3 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 2 月 4 日
編集済み: KALYAN ACHARJYA 2019 年 2 月 4 日
@Luna yes. It seems so. Hello @msr16 for circshift, read here and implement, any problem let me know here.
msr16
msr16 2019 年 2 月 4 日
編集済み: msr16 2019 年 2 月 4 日
@KALYAN ACHARJYA it is for finding permutation of n numbers

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


Rose May Hidalgo
Rose May Hidalgo 2021 年 1 月 8 日
B=3*eye(size)A)-A)
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 4 日
B = 3 * (eye(size(A)) - A)

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


Renesh Dayah
Renesh Dayah 2022 年 5 月 4 日
create variable for x for (-π,π)
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 4 日
For the most part, it is not possible to create a variable in MATLAB that is restricted to a certain range -- not without creating your own object oriented class and being willing to use strict rules about how to assign values to the variables.
You can create symbolic variables and give the symbolic engine assumptions about the range, in a way that in some cases the symbolic engine can reason about the value
syms x
Pi = sym(pi);
assume(x > -Pi & x < Pi)
assumptions
ans = 
isAlways( imag(sin(x)) == 0)
ans = logical
1
In some cases you can configure optimization variables to be in a particular range; see https://www.mathworks.com/help/optim/ug/optimconstr.html

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


Dhruv
Dhruv 2023 年 10 月 23 日
sin(pi/4)+e^-3/2
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 23 日
The sin(pi/4) part can be written as
sin(pi/4)
The e^ part should be written as exp
exp(-3/2)
Note however, that instead of sin(pi/4) you get better precision if you write
sinpi(1/4)

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

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by