| 8 | 1/1 | 返回列表 |
| 查看: 1084 | 回復(fù): 7 | ||
lkcool7新蟲 (初入文壇)
|
[求助]
運(yùn)行matlab程序中自定義函數(shù)時(shí)出問題了,還請(qǐng)大神幫忙!謝謝 已有1人參與
|
|
我自定義了三個(gè)函數(shù)Y1(),Y2(),Y3(),三個(gè)函數(shù)只是內(nèi)部參數(shù)k發(fā)生變 在這里我給出Y1()代碼 function h=Y1(x) %參數(shù) k=0.1884;l=25.5;pA=1070; u=cosh(k*x)+cos(k*x)-((sinh(k*x)+sin(k*x))*(cosh(k*l)-cos(k*l)))/(sinh(k*l)-sin(k*l)); a=sqrt(pA*eval(int(u^2,x,0,l))); h=u/a; 下面是主程序,目的在于繪出Y1,Y2,Y3曲線圖。 clear clc x=0.1:0.1:25.5; for m=1:1:255 y1(m)=Y1(x(m)); end for m=1:1:255 y2(m)=Y2(x(m)); end for m=1:1:255 y3(m)=Y3(x(m)); end plot(x,y1); hold on plot(x,y2); hold on plot(x,y3); hold on 運(yùn)行是程序在調(diào)用Y1()時(shí)出錯(cuò),提示為 ??? Undefined function or method 'int' for input arguments of type 'double'. Error in ==> Y1 at 4 a=sqrt(pA*eval(int(u^2,x,0,l))); Error in ==> zhenxing at 6 y1(m)=Y1(x(m)); 也就是在Y1()中調(diào)用int積分函數(shù)時(shí)出錯(cuò),為什么會(huì)這樣。????如果我將a=sqrt(pA*eval(int(u^2,x,0,l)));提前算出,直接將這行替換為a=169.2216;卻可以運(yùn)行,并最后繪制出我要的曲線。但是在我自己定義的函數(shù)中調(diào)用int()居然會(huì)出錯(cuò)?求大神幫助! 謝謝 |
金蟲 (初入文壇)
新蟲 (初入文壇)
金蟲 (初入文壇)
木蟲 (正式寫手)
新蟲 (初入文壇)
|
謝謝回答,我已解決了問題,確實(shí)發(fā)覺函數(shù)Y1(x)中的u為數(shù)值而非符號(hào)表達(dá)式。然后我建立了符號(hào)變量 syms x k l 將int(u,x,0,l) 計(jì)算出來 下面是我解決問題后的代碼 function h=Y1(x) k=0.1884;l=25.5;pA=1070; u=cosh(k*x)+cos(k*x)-((sinh(k*x)+sin(k*x))*(cosh(k*l)-cos(k*l)))/(sinh(k*l)-sin(k*l)); %p為符號(hào)積分int(u^2,x,0,l)結(jié)果,為符號(hào)表達(dá)式 p=1/4*-4*cosh(k*l)*cos(k*l)^2*exp(3*k*l)-4*sin(k*l)^2*cosh(k*l)*exp(3*k*l)+4*sinh(k*l)*cos(k*l)^3*exp(2*k*l)-sin(k*l)*sinh(k*l)-cosh(k*l)*cos(k*l)+cosh(k*l)^2-4*cos(k*l)^3*exp(k*l)+8*sin(k*l)*sinh(k*l)*k*exp(2*k*l)*l+4*exp(2*k*l)*sinh(k*l)*sin(k*l)^2*cos(k*l)+4*sin(k*l)^2*cos(k*l)*exp(3*k*l)-4*sin(k*l)^2*cos(k*l)*exp(k*l)+4*cos(k*l)^3*exp(3*k*l)-exp(4*k*l)*cosh(k*l)^2+4*sinh(k*l)*cosh(k*l)*exp(3*k*l)*sin(k*l)+4*cosh(k*l)*cos(k*l)*exp(3*k*l)*sin(k*l)-4*sinh(k*l)*cosh(k*l)*sin(k*l)*exp(k*l)-4*exp(2*k*l)*cosh(k*l)^2*k*l-4*sinh(k*l)*cosh(k*l)*cos(k*l)^2*exp(2*k*l)+4*cosh(k*l)*cos(k*l)*sin(k*l)*exp(k*l)+4*exp(2*k*l)*cos(k*l)^2*k*l+exp(4*k*l)*sinh(k*l)*cosh(k*l)+exp(4*k*l)*sinh(k*l)*sin(k*l)+exp(4*k*l)*sin(k*l)*cos(k*l)-exp(4*k*l)*sin(k*l)*cosh(k*l)+4*sin(k*l)^2*cosh(k*l)*exp(k*l)-4*cosh(k*l)^2*sin(k*l)*exp(k*l)+exp(4*k*l)*cosh(k*l)*cos(k*l)-exp(4*k*l)*sinh(k*l)*cos(k*l)-4*cosh(k*l)^2*exp(3*k*l)*sin(k*l)+4*cosh(k*l)*cos(k*l)^2*exp(k*l)+4*sin(k*l)^2*sinh(k*l)*exp(k*l)+4*sin(k*l)^2*sinh(k*l)*exp(3*k*l)+sinh(k*l)*cosh(k*l)-sinh(k*l)*cos(k*l)-sin(k*l)*cosh(k*l)+sin(k*l)*cos(k*l)+2*exp(2*k*l)*sin(k*l)*cos(k*l)-2*exp(2*k*l)*sin(k*l)*cosh(k*l)+2*exp(2*k*l)*sinh(k*l)*cosh(k*l)-2*exp(2*k*l)*sinh(k*l)*cos(k*l))/k/(-cosh(k*l)^2+cos(k*l)^2+2*sin(k*l)*sinh(k*l))*exp(-2*k*l); a=sqrt(pA*p); h=u/a; |
新蟲 (正式寫手)
|
樓上說的是對(duì)的,x和u是符號(hào)變量,才能使用 int()函數(shù),你的代碼里面一是沒有進(jìn)行定義,二是你把它理解成常數(shù)了。所以會(huì)報(bào)錯(cuò),找不到該函數(shù)(你把int函數(shù)用錯(cuò)了) 發(fā)自小木蟲Android客戶端 |
木蟲 (正式寫手)

| 8 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 322求調(diào)劑 +3 | X123- 2026-03-14 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 0703化學(xué)調(diào)劑 +4 | 妮妮ninicgb 2026-03-21 | 4/200 |
|
|
[考研] 307求調(diào)劑 +3 | 余意卿 2026-03-18 | 3/150 |
|
|
[考研] 299求調(diào)劑 +5 | shxchem 2026-03-20 | 7/350 |
|
|
[考研] 266求調(diào)劑 +3 | 哇呼哼呼哼 2026-03-20 | 3/150 |
|
|
[考研] 279求調(diào)劑 +5 | 紅衣隱官 2026-03-21 | 5/250 |
|
|
[考研] 一志愿天津大學(xué)化學(xué)工藝專業(yè)(081702)315分求調(diào)劑 +12 | yangfz 2026-03-17 | 12/600 |
|
|
[考研] 一志愿南京理工大學(xué)085701資源與環(huán)境302分求調(diào)劑 +4 | 葵梓衛(wèi)隊(duì) 2026-03-18 | 6/300 |
|
|
[考研] 323求調(diào)劑 +3 | 洼小桶 2026-03-18 | 3/150 |
|
|
[考研] 一志愿西安交通大學(xué) 學(xué)碩 354求調(diào)劑211或者雙一流 +3 | 我想要讀研究生 2026-03-20 | 3/150 |
|
|
[考研] 353求調(diào)劑 +3 | 拉鉤不許變 2026-03-20 | 3/150 |
|
|
[考博] 招收博士1-2人 +3 | QGZDSYS 2026-03-18 | 3/150 |
|
|
[考研] 求調(diào)劑 +3 | 暗涌afhb 2026-03-16 | 3/150 |
|
|
[考研] 生物學(xué)調(diào)劑招人!! +3 | 山海天嵐 2026-03-17 | 4/200 |
|
|
[考研] 材料考研調(diào)劑 +3 | xwt。 2026-03-19 | 3/150 |
|
|
[考研] 334求調(diào)劑 +3 | 志存高遠(yuǎn)意在機(jī)?/a> 2026-03-16 | 3/150 |
|
|
[考研] 一志愿南京大學(xué),080500材料科學(xué)與工程,調(diào)劑 +4 | Jy? 2026-03-16 | 4/200 |
|
|
[考研] 283求調(diào)劑 +3 | 聽風(fēng)就是雨; 2026-03-16 | 3/150 |
|
|
[考研]
|
zhouzhen654 2026-03-16 | 3/150 |
|
|
[考研] 機(jī)械專碩325,尋找調(diào)劑院校 +3 | y9999 2026-03-15 | 5/250 |
|