Ask your own question, for FREE!
Mathematics 21 Online
OpenStudy (anonymous):

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))

OpenStudy (anonymous):

@dan815

OpenStudy (dan815):

therse a lota fu in there

OpenStudy (anonymous):

what?

OpenStudy (dan815):

okay what is this doing there finitediff(u(ii))<tol

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

try it on matlab. the function handles just prints out the function. instead of giving the answer.

OpenStudy (dan815):

was there some typo here u(ii+1) = u(ii)-f(u(ii))/finitediff(u(ii))<tol

OpenStudy (dan815):

why do u have a boolean check in the middle of an expression like that

OpenStudy (anonymous):

because i've suppose to set tolerance

OpenStudy (anonymous):

i'm*

OpenStudy (dan815):

oh that works?

OpenStudy (dan815):

cant u just let it evaluate the expression and then round off your total array

OpenStudy (dan815):

gimme ur code for finitediff

OpenStudy (dan815):

i dont have the fn

OpenStudy (dan815):

its not even plotting f right

OpenStudy (anonymous):

i know thats the problem

OpenStudy (dan815):

show me the equation for f and ill go thru it

OpenStudy (anonymous):

function [d]= finitediff(f,x)

OpenStudy (anonymous):

h = sqrt(eps);

OpenStudy (anonymous):

d = (f(x+h) - f(x))/h;

OpenStudy (anonymous):

end

OpenStudy (turingtest):

please post this kind of thing in the computer science section next time thanks

OpenStudy (dan815):

okay i made it plot

OpenStudy (anonymous):

computer science? but its a maths course

OpenStudy (dan815):

now u gotta make ur newtons method work

OpenStudy (anonymous):

how did u plot it? if the function isn't working

OpenStudy (dan815):

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)

OpenStudy (anonymous):

the function is not even working. in the command window, it prints out the function of Re, Drag and f.

OpenStudy (dan815):

i added some missing periods in ur fn def

OpenStudy (anonymous):

fn deff?

OpenStudy (dan815):

function definition

OpenStudy (dan815):

it shud show u a graph, just look at it and tell me if that is the right graph u are looking for

OpenStudy (anonymous):

no actually its the wrong graph, its like a piece wise graph. discontinuous

OpenStudy (dan815):

oh is it

OpenStudy (anonymous):

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)

OpenStudy (dan815):

do u have a image or a file with what hte real equation looks like

OpenStudy (dan815):

that is a mess to decode

OpenStudy (anonymous):

yup.

OpenStudy (anonymous):

OpenStudy (anonymous):

the long one(f(u)) consist of all equations.

OpenStudy (dan815):

okay

OpenStudy (dan815):

is D=0.0064

OpenStudy (anonymous):

yeah

OpenStudy (anonymous):

for this code i should get the answer:u= -.0584 though my coding is a fail.

OpenStudy (dan815):

oh i see

OpenStudy (dan815):

so u are gonna use newtowns method to find the roots for f(u) right

OpenStudy (anonymous):

yeah, the new velocity.

OpenStudy (dan815):

ok hmm and u are also gonna diffentiate numerically?

OpenStudy (anonymous):

no not numerically, but using the function finitediff that i created

OpenStudy (dan815):

hmm

OpenStudy (dan815):

lets get this fn to work for now

OpenStudy (dan815):

it seems like a pretty easy question i think numerical derivative is okay too tbh

OpenStudy (anonymous):

what is this fn?

OpenStudy (anonymous):

yeah its easy to do the nwtons method, but the @ function don't work.

OpenStudy (dan815):

http://prntscr.com/5qccgd

OpenStudy (dan815):

rewrite the fn

OpenStudy (anonymous):

what do mean?

OpenStudy (dan815):

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)

OpenStudy (dan815):

here u go u can mess with it

OpenStudy (dan815):

got rid of the function way, just to see what this thing is supposed to look like

OpenStudy (dan815):

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

OpenStudy (anonymous):

i don't understand this

OpenStudy (dan815):

i wrote your function as it is instead of using @(u) s

OpenStudy (anonymous):

how am i going to use newtons method on this?

OpenStudy (dan815):

so it only accepts 1 input of u at a time

OpenStudy (dan815):

and u has to be defined earlier

OpenStudy (dan815):

u are seeing what the value at each u is and adding it to a matrix thats all

OpenStudy (dan815):

just look over the function, it the graph looks crazy..

OpenStudy (anonymous):

let me understand this. i'm lost

OpenStudy (anonymous):

i'm just confused. how i'm going to derive it and apply newtions method on this

OpenStudy (dan815):

okay

OpenStudy (anonymous):

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.

OpenStudy (dan815):

there are some annoying matrix dimension problems that are coming up because u have functions embedded in functions

OpenStudy (dan815):

im not sure how to make it evalualte one variable at a time for each function

OpenStudy (anonymous):

i greatly appreciate your help.

OpenStudy (dan815):

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)

OpenStudy (dan815):

here u go its fixed

OpenStudy (dan815):

there is a zero at -0.something

OpenStudy (dan815):

http://prntscr.com/5qd21t

OpenStudy (anonymous):

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.

OpenStudy (dan815):

now to do newtons method

OpenStudy (anonymous):

its not wotking.

OpenStudy (dan815):

|dw:1420819413068:dw|

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!