Solving an Equation for Different Values of Constants

I am solving a simple equation for x which has constants a b and c. a and b are matrices and c is a constant value. I want 4 values of x for 4 values of a and b. How can I do that? I have written the following code but it doesnt work.
>> a=[2 1 2 3];
>> b=[6 7 8 89];
>> c=123;
>> syms x positive
>> eqn=x^2*a*c-x*b*c+20;
>> y=solve(eqn,x)
This code doesn't work The code works for one value of a and b. For example
>> eqn=x^2*a(1)*c-x*b(1)*c+20;
>> y=solve(eqn,x)
This way it gives one answer. But I want 4 answers for x.

 Accepted Answer

f = 25;
A = 1000;
b = 200;
d = 450;
B = 0.85;
E = 200000;
e = linspace(0,0.003,15);
s = (f*(2*(e/0.002)-(e/0.002).^2));
syms a positive
v = sym(zeros(length(e),1));
for i = 1:length(e)
eqn = (a^2)*(s(i)*b)+((a*e(i)*A*E)-(e(i)*B*E*A*d));
temp = vpasolve(eqn,a);
temp2 = temp(temp>0);
if isempty(temp2)
fprintf('Warning: eqn has no positive solutions for i = %d, and has %d negative solutions\n', i, length(temp));
v(i) = nan;
elseif length(temp2) > 1
fprintf('Warning: eqn has %d positive solutions for i = %d, first is selected\n', length(temp2) );
v(i) = temp2(1);
else
v(i) = temp2;
end
end
disp(v)

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!