I am trying to find the roots of this equation but my code doesn't work. It keeps saying theta0 is unrecognized,
1 次查看(过去 30 天)
显示 更早的评论
fun = @f;
x0 = [0 6.28];
z = fzero(fun,x0)
function theta0 = f(y0,yf,v0,x)
y0= 2;
yf= 1;
v0=20;
x=35;
theta0= x*tan(theta0)-4.905*(x^2)/((v0^2)*((cos(theta0))^2))-(y0-yf);
end
0 个评论
回答(3 个)
Arif Hoq
2022-3-1
编辑:Arif Hoq
2022-3-1
save your function. you have to define your variable theta0 in this function.
function y = f(x)
y0= 2;
yf= 1;
v0=20;
theta=35;
y= x*tan(theta0)-4.905*(x^2)/((v0^2)*((cos(theta0))^2))-(y0-yf);
end
then call this function in a diffrent script(m file)
fun = @f;
x= [0 6.28];
z = fzero(fun,x)
John D'Errico
2022-3-1
It appears that your equation is:
theta0= x*tan(theta0)-4.905*(x^2)/((v0^2)*((cos(theta0))^2))-(y0-yf);
and you wish to solve for x that satisfies this implicit function of x, where theta0 = 35 is given also?
The trick is to write it as a problem where the function would be zero. Do that by subtracting theta0 from both sides. Now your problem looks like:
x*tan(theta0)-4.905*(x^2)/((v0^2)*((cos(theta0))^2))-(y0-yf) - theta0 == 0
Now it is time to write some MATLAB code. We should verify it has any solution at all.
y0 = 2;
yf = 1;
v0 = 20;
theta0 = 35;
F = @(x) x*tan(theta0)-4.905*(x.^2)/((v0^2)*((cos(theta0))^2))-(y0-yf) - theta0;
PLOT IT!!!!
fplot(F,[-100,100])
So your problem, if it is assumed to be a function of x, has NO point where it crosses zero.
As such fzero would fail, although solve would find there are a pair of complex roots, since this is just a quadratic equation. THus
syms x
vpasolve(x*tan(theta0)-4.905*(x.^2)/((v0^2)*((cos(theta0))^2))-(y0-yf) - theta0)
Torsten
2022-3-2
function main
theta0 = 0;
theta = fzero(@f,theta0)
end
function res = f(theta)
y0 = 2;
yf = 1;
v0 = 20;
x = 35;
res = x*tan(theta)-4.905*(x^2)/((v0^2)*((cos(theta))^2))-(y0-yf);
end
1 个评论
Walter Roberson
2022-3-2
I have a suspicion that they intend x to be a parameter, and need to know about parameterizing functions
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!