Filter löschen
Filter löschen

I am trying to find the roots of this equation but my code doesn't work. It keeps saying theta0 is unrecognized,

1 Ansicht (letzte 30 Tage)
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

Antworten (3)

Arif Hoq
Arif Hoq am 1 Mär. 2022
Bearbeitet: Arif Hoq am 1 Mär. 2022
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
John D'Errico am 1 Mär. 2022
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)
ans = 

Torsten
Torsten am 2 Mär. 2022
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

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by