does anybody do matlab? i need help with fixing my code.
clear all;
clc;
den_b = 8550;
den_f = 1100;
visc_f = 0.1;
D_b = 0.0064;
g = 9.81;
u = 0.1;
step = 0.01;
n = 100;
tol = 10^-4;
Re = @(u)(D_b*abs(u)*den_f)/visc_f
bouyancy = (den_f-den_b)*(pi/6).*D_b.^3.*g
Drag = @(u)((2.25./Re(u).^0.31)+(0.358.*Re(u).^0.06)).^3.45
CirArea =(pi/4).*D_b^2
f =@(u) bouyancy-(Drag(u).*CirArea*den_f.*u*abs(u)/2)
for ii = 1:n
u(ii+1) = u(ii)-f(u(ii))/finitediff(u(ii))
@dan815
therse a lota fu in there
what?
okay what is this doing there finitediff(u(ii))<tol
basically i have to use newtons method. function and find its derivative. but the function cannot be differentiated, since its a function within a function. i'm using finite derivaive function to find its derivative.
try it on matlab. the function handles just prints out the function. instead of giving the answer.
was there some typo here u(ii+1) = u(ii)-f(u(ii))/finitediff(u(ii))<tol
why do u have a boolean check in the middle of an expression like that
because i've suppose to set tolerance
i'm*
oh that works?
cant u just let it evaluate the expression and then round off your total array
gimme ur code for finitediff
i dont have the fn
its not even plotting f right
i know thats the problem
show me the equation for f and ill go thru it
function [d]= finitediff(f,x)
h = sqrt(eps);
d = (f(x+h) - f(x))/h;
end
please post this kind of thing in the computer science section next time thanks
okay i made it plot
computer science? but its a maths course
now u gotta make ur newtons method work
how did u plot it? if the function isn't working
clear all; clc; den_b = 8550; den_f = 1100; visc_f = 0.1; D_b = 0.0064; g = 9.81; u = 0.1; step = 0.01; n = 100; tol = 10^-4; Re = @(u)(D_b*abs(u)*den_f)/visc_f bouyancy = (den_f-den_b)*(pi/6).*D_b.^3.*g Drag = @(u)((2.25./Re(u).^0.31)+(0.358.*Re(u).^0.06)).^3.45 CirArea =(pi/4).*D_b^2 f =@(u) bouyancy-(Drag(u).*CirArea*den_f.*u.*abs(u)./2) %for ii = 1:n %u(ii+1) = u(ii)-f(u(ii))/finitediff(u(ii)) %end uarray = 0.1:0.1:100; yarray = f(uarray); plot(uarray,yarray)
the function is not even working. in the command window, it prints out the function of Re, Drag and f.
i added some missing periods in ur fn def
fn deff?
function definition
it shud show u a graph, just look at it and tell me if that is the right graph u are looking for
no actually its the wrong graph, its like a piece wise graph. discontinuous
oh is it
there is something wrong with these. i'm not sure what. Re = @(u)(D_b*abs(u)*den_f)/visc_f bouyancy = (den_f-den_b)*(pi/6).*D_b.^3.*g Drag = @(u)((2.25./Re(u).^0.31)+(0.358.*Re(u).^0.06)).^3.45 CirArea =(pi/4).*D_b^2 f =@(u) bouyancy-(Drag(u).*CirArea*den_f.*u.*abs(u)./2)
do u have a image or a file with what hte real equation looks like
that is a mess to decode
yup.
the long one(f(u)) consist of all equations.
okay
is D=0.0064
yeah
for this code i should get the answer:u= -.0584 though my coding is a fail.
oh i see
so u are gonna use newtowns method to find the roots for f(u) right
yeah, the new velocity.
ok hmm and u are also gonna diffentiate numerically?
no not numerically, but using the function finitediff that i created
hmm
lets get this fn to work for now
it seems like a pretty easy question i think numerical derivative is okay too tbh
what is this fn?
yeah its easy to do the nwtons method, but the @ function don't work.
rewrite the fn
what do mean?
p_f=1100 p_p=8550 u_f=0.1 D=0.0064 g=9.81 %u=-10:0.01:10 i=0 for u=-1:0.01:1 i=i+1; Re=D*abs(u)*p_f/u_f; y(i)=(p_f-p_p)*pi/6*D^3*g*(-2.25/(Re)^0.31+0.358*Re^0.06)^3.45*pi/4*D^2*p_f*u*abs(u)/2; end plot(y)
here u go u can mess with it
got rid of the function way, just to see what this thing is supposed to look like
looks messed up.. check of the function but use that method forget the function definitions for now, just see what the value at each u is and graph it
i don't understand this
i wrote your function as it is instead of using @(u) s
how am i going to use newtons method on this?
so it only accepts 1 input of u at a time
and u has to be defined earlier
u are seeing what the value at each u is and adding it to a matrix thats all
just look over the function, it the graph looks crazy..
let me understand this. i'm lost
i'm just confused. how i'm going to derive it and apply newtions method on this
okay
i'm just lost now. is it possible you can just fix my code and see where i'm going wrong? the function handle is just printing out the function and not working.
there are some annoying matrix dimension problems that are coming up because u have functions embedded in functions
im not sure how to make it evalualte one variable at a time for each function
i greatly appreciate your help.
clear all; clc; den_b = 8550; den_f = 1100; visc_f = 0.1; D_b = 0.0064; g = 9.81; u = 0.1; step = 0.01; n = 100; tol = 10^-4; Re = @(u)(D_b*abs(u)*den_f)/visc_f bouyancy = (den_f-den_b)*(pi/6).*D_b.^3.*g Drag = @(u)((2.25./Re(u).^0.31)+(0.358.*Re(u).^0.06)).^3.45 CirArea =(pi/4).*D_b^2 f =@(u) bouyancy-(Drag(u).*CirArea*den_f.*u.*abs(u)./2) %u=-10:0.01:10 %Re=D*abs(u.)*p_f/u_f %y=(p_f-p_p)*pi/6*D^3*g(-2.25/(Re)^0.31+0.358*Re^0.06)^3.45*pi/4*D^2*p_f*u.*abs(u.)/2 %for ii = 1:n %u(ii+1) = u(ii)-f(u(ii))/finitediff(u(ii)) %end uarray = -100:0.1:100; yarray = f(uarray); plot(uarray,yarray)
here u go its fixed
there is a zero at -0.something
functions embedded in functions, thats the thn. i was told if i use function handle for each and ttry to put then together like i have it'll work. and i got it to work before. but matlab crashed, so i lost everything.
now to do newtons method
its not wotking.
|dw:1420819413068:dw|
Join our real-time social learning platform and learn together with your friends!