Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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