How to solve a equation with a single variable for a range of values?
Show older comments
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 Comments
David Hill
on 27 Sep 2019
You need beta to solve for L2 given an array of alphas.
Abinav Shankar
on 27 Sep 2019
Answers (1)
darova
on 27 Sep 2019
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 Comment
Abinav Shankar
on 27 Sep 2019
Categories
Find more on Common Operations 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!