Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I need to send variables to solve(). How do I do it?

1 回表示 (過去 30 日間)
Kushagra Vidyarthi
Kushagra Vidyarthi 2015 年 2 月 27 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello,
I have to send 3 variables to solve(). I have defined two of these variables such that their values are precomputed in a loop. The value changes every loop. So I need to define the as variables. I need to use the solve command to get the value of the third variable. But I cannot do that and the output is a symbol. I wrote the following loop to do this.
for i = 1:1:60
syms lambda;
a = (V(i)*cos(D(i)/W))/(omega*R);
b = (V(i)*sin(D(i)/W))/(omega*R);
temp = solve(Ct-(2*lambda*sqrt(a^2 + (b+lambda)^2))==0,lambda);
end
V,D are variables with a value changing every iteration of the loop (predefined). W, omega,Ct and R have constant values.
Help appreciated. Thanks
Kushagra

回答 (1 件)

Star Strider
Star Strider 2015 年 2 月 27 日
編集済み: Star Strider 2015 年 2 月 27 日
I would use fzero:
Ct = randi(100); % Pick A Number
R = randi(50); % Pick A Number
W = randi(10); % Pick A Number
omega = 2*pi*rand; % Pick A Number
V = randi(10, 1, 60); % Pick A Randonm Vector
D = 2*pi*rand(1,60); % Pick A Randonm Vector
for k1 = 1:length(V)
a = (V(k1)*cos(D(k1)/W))/(omega*R);
b = (V(k1)*sin(D(k1)/W))/(omega*R);
fcn = @(lambda) Ct-(2*lambda*sqrt(a^2 + (b+lambda)^2));
est_lambda(k1) = fzero(fcn, randi(10));
end
It’s best to not use ‘i’ and ‘j’ as variables, including as loop counters. MATLAB uses them for its imaginary operators, and using them otherwise can cause confusion.

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by