How to solve a equation with a single variable for a range of values?

10 次查看(过去 30 天)
I have a linear equation with 2 variables. I want to calculate the value of one variable for a given rane of my second variable.
These are my formula and alpha and L2 are my variable. I want to calculate the value of L2 for alpha from 0 to 42 in steps of 1. But when I solve the equation, I still get the answer in terms of L2 and not a numerical value.
Here is my code
clc;
clear all;
%Getting the input of Constant Values
syms L2;
L1=input('Enter the value of L1:');
R1=input('Enter the value of R1:');
R2=input('Enter the value of R2:');
R3=input('Enter the value of R3:');
a=input('Enter the value of a:');
%Rewriting all variables in terms of L2
alpha = 1:1:42;
L3=sqrt(L1^2+L2^2+2*L1*L2.*cos(alpha));
cosbeta = (L1^2+L3.^2-L2^2)./(2*L1.*L3);
beta=acos(cosbeta);
theta1=(180-beta)*(pi/180);
theta2=alpha*(pi/180);
theta3=(180-alpha+beta)*(pi/180);
%Computing L2
eqn=a-(L1+theta1*R1+theta2*R2+theta3*R3+L3);
solve(eqn,L2);
  2 个评论
Abinav Shankar
Abinav Shankar 2019-9-27
Actually my beta is dependent on L1, L2 and L3. L1 is a constant, L3 is again dependent on L1, L2 and alpha. So technically my beta is dependent on L2 and alpha. I can rewrite my entire equation in terms of L2 and alpha.Annotation 2019-09-27 111611.jpg

请先登录,再进行评论。

回答(1 个)

darova
darova 2019-9-27
I think it can be kind of complicated for symbolic calculations
clc,clear
syms a L2
% define your constants
eqn = % your long expression
ezplot(eqn)
Or another aproach: examine if there are roots (F == 0)
F = matlabFunction( eqn,'vars',[a L2] );
[X,Y] = meshgrid(0:10);
surf(X,Y,F(X,Y))
xlabel('a axis')
ylabel('L2 axis')
  1 个评论
Abinav Shankar
Abinav Shankar 2019-9-27
I think its a bit too complicated. I was able to easily solve it for a single value instead of a range. Then I used the solution in a for loop to generate solution for a range of values. It's slow but atleast it gets the job done.
Thanks.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by